重複の可能性:
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>
ただし、このコードはショートカットを作成しません。
ショートカットを作成するにはどうすればよいですか?