デバイスが起動したときにアプリケーションを起動したいが、許可、インテントフィルタ、カテゴリを追加しても機能しない。手動で起動したアプリケーションでもBOOT_COMPLETEDブロードキャストが受信されない
私はアンドロイド3.1の後、ユーザーが手動でブロードキャストを開始する前にアプリを起動できないことを知っています。
私はインストール後数回アプリを実行しましたが、それでも動作しません。
以下は私のコードです。
マニフェスト:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
...
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver
android:name=".Receiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
放送受信機クラス。
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = "action : " + intent.getAction();
Log.d("MyTag", action);
Toast.makeText(context, action, Toast.LENGTH_SHORT).show();
context.startActivity(new Intent(context, MainActivity.class));
}
}
インテントフィルタごとにレシーバを分けてみると、マニフェストの合併によってレシーバが動作しなくなる問題が発生することがあります。私はあなたと同様の問題に直面し、私はこのトリックで働いた。 – Kushan