可能重复:
在Android主屏幕上创建快捷方式
我在我的 Activity(HomeActivity.class)中有一个 TextView
和一个 Button
。
目标:当我点击 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>
但这段代码并不会创建任何快捷方式。
我该如何创建快捷方式?