メインアクティビティのアプリケーションアイコンを作成するにはどうすればよいですか?
ホーム画面ページのアプリケーションアイコンをカスタマイズするためのショートカットを作成したいと思います。
アプリケーションのインストール後にメイン画面に適用したい。
これどうやってするの ?
メインアクティビティのアプリケーションアイコンを作成するにはどうすればよいですか?
ホーム画面ページのアプリケーションアイコンをカスタマイズするためのショートカットを作成したいと思います。
アプリケーションのインストール後にメイン画面に適用したい。
これどうやってするの ?
ショートカットを追加する方法
private void addShortcut(){
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// Shortcut name
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
shortcutIntent.putExtra("duplicate", false);
ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
// Shortcut icon
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcutIntent);
}
ショートカットを削除する方法
private void delShortcut(){
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
// Shortcut adı
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
String appClass = this.getPackageName() + "." +this.getLocalClassName();
ComponentName comp = new ComponentName(this.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
sendBroadcast(shortcut);
}
OnCreateでメソッドを呼び出す
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
delShortcut();
addShortcut();
ショートカットを追加するためのアクセス許可
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
アイコンを作成し、描画可能なフォルダーに入れてから、マニフェストに入れます...
<application
android:icon="@drawable/your_icon"
android:label="@string/app_name" >