【发布时间】:2014-01-02 19:53:24
【问题描述】:
我正在尝试更改 Intent.EXTRA_SHORTCUT_ICON_RESOURCE 的来源
public class ShortcutActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The meat of our shortcut
final Intent shortcutIntent = new Intent(this, ShortcutResult.class);
ShortcutIconResource iconResource = Intent.ShortcutIconResource
.fromContext(this, R.drawable.test);
// The result we are passing back from this activity
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Test");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, intent);
finish(); // Must call finish for result to be returned immediately
}
我访问了另一个启动服务的活动。当服务启动和停止时,我希望能够在两个图像之间交替。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedPrefs = getApplicationContext().getSharedPreferences("eePrefs2",
Context.MODE_PRIVATE);
editor = sharedPrefs.edit();
if (sharedPrefs.getBoolean("service_running", false) == false) {
startService(new Intent(this, service.class));
editor.putBoolean("service_running", true);
ShortcutIconResource iconResource = Intent.ShortcutIconResource
.fromContext(this, R.drawable.test);
} else if (sharedPrefs.getBoolean("service_running", false) == true) {
stopService(new Intent(this, service.class));
editor.putBoolean("service_running", false);
ShortcutIconResource iconResource = Intent.ShortcutIconResource
.fromContext(this, R.drawable.test2);
}
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, intent);
editor.commit();
finish();
}
有什么想法吗?
【问题讨论】:
标签: android android-intent icons shortcut