私はAndroidアプリケーションに取り組んでいます。これをランチせずにアプリケーションのショートカットを作成したいです。このコードも試しましたが、これではアプリケーションを少なくとも1つロードする必要があります.しかし、デバイスアプリケーションにアプリケーションをインストールするときにアプリケーションのショートカットを作成したい昼食は必須ではありません。Flipkart.it と同様に、デバイスにインストールするとアプリケーションのショートカットが自動的に生成され、アプリを起動する必要はありません。
また、Broadcaster Receiver を使用してこれを実行しようとしましたが、成功しませんでした。コードは次のようになります。
Manifeasts.xml
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<receiver android:name=".fragmentTesting.ApplicationBroadcastService">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
</intent-filter>
</receiver>
ApplicationBroadcastService.java
public class ApplicationBroadcastService extends BroadcastReceiver {
private static final String TAG = "onReceive";
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "IN Receive Call");
Intent shortcutIntent = new Intent(context, RecycleViewTesting.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "MyAppName");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_menu_send));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
}
}
このコードでは、アプリのインストール時にブロードキャスト レシーバーが呼び出されません。