我有一个应用程序,它使用广播服务在重新启动后继续我的未决意图,但它不能正常工作。重新启动手机后,我会收到弹出通知MyAppsName has stopped working
。我为它制作的日志没有出现。
的manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.idkbro.pashchallenge">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<application
android:allowBackup="true"
android:name=".BaseApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".AlertReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name=".NotificationService"
android:exported="true"></service>
</application>
BootReceiver:
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Xu", "Boot receiver is working");
}
答案 0 :(得分:-1)
只需在接收器类中添加:
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
Log.i("Xu", "Boot receiver is working");
}
从manifest reciver标记中删除权限和类别意图过滤器,如:
<receiver
android:name=".BootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>