ショートカットの起動に失敗しました:アプリケーションが携帯電話にインストールされていません
-
26-09-2019 - |
質問
Android のアクティビティの 1 つへのデスクトップ ショートカットを作成しようとしています。私が読んだすべての tuto の例で機能するコードを使用します。
final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
ComponentName name = new ComponentName(getPackageName(), ".MyActivity");
shortcutIntent.setComponent(name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "blabla");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
finish();
そして、MAIN アクションをアクティビティに追加しました。
<activity android:label="@string/app_name" android:name=".MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
その結果、アプリケーションは起動できなくなります。
Logcat ではすべて問題ないようです。
10-01 01:17:51.591: INFO/ActivityManager(2424): Starting activity: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=my.package.name/.MyActivity bnds=[125,384][235,522] (has extras) }
そして、ホームにはアプリケーションがインストールされていないことが表示されます。
助けてください。私は完全に道に迷っており、問題を解決するのに数時間を費やし、入手できるすべての情報を読みました。
どうもありがとうございます!
解決
これを試して:
- を取り除く
<intent-filter>
- を取り除く
ACTION_MAIN
そしてただ使用してくださいnew Intent(this, MyActivity.class)
- マニフェスト内の要素に android:exported="true" を追加します
他のヒント
あなたがあなたの活動を持っている場合に発生する可能性が最初のランチャーとして、あなたのAndroidManifest.xmlで2回宣言して、同じように宣言ます:
<activity android:name=".MyActivity" />
所属していません StackOverflow