我試圖創建應用程序快捷方式,我指的是一些文件和我使用Android的安裝快捷方式,但快捷方式圖標不顯示
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
launchIntent.setAction(Intent.ACTION_MAIN);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplication(), MainActivity.class));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test app");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.mipmap.ic_launcher));
getApplicationContext().sendBroadcast(intent);
我也允許添加到我的清單
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
但是,它可以在我的舊HTC手機(android 4.4)上正常工作,但不會在另一部手機上使用三星s6(android7.0)。
任何人都可以幫助我嗎?謝謝!
這是你自己的應用程序?是否有一個原因,你沒有從AndroidManifest做到這一點? –