可能重复:
Android 在主屏幕上创建快捷方式
我有一个TextView
,Button
在我的活动中(HomeActivity.class)。
目标:当我单击它时,Button
它应该创建一个快捷方式,其中默认的 android 图像作为图标和文本,如在TextView
.
到目前为止,我发现我们可以使用创建快捷方式ACTION_CREATE_SHORTCUT
这是我到目前为止的代码:
Intent result = new Intent(android.content.Intent.ACTION_CREATE_SHORTCUT);
result.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent(getApplicationContext(), Editor.class));
result.putExtra(TodoDbAdapter.KEY_ROWID,rowid);
result.putExtra(Intent.EXTRA_SHORTCUT_NAME,textView.getText());
result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(HomeActivity.this,
R.drawable.icon));
setResult(RESULT_OK, result);
我的清单文件:
<activity android:name=".HomeActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
但是此代码不会创建任何快捷方式。
如何创建快捷方式?