Java Android:重新启动后启动广播不工作
我有一个应用程序,它使用广播服务在重新启动后继续我的未决意图,但它没有按预期工作。重新启动手机后,我会收到弹出通知,提示MyAppsName已停止工作。我为它做的日志没有出现 manifest.xml:Java Android:重新启动后启动广播不工作,java,android,xml,Java,Android,Xml,我有一个应用程序,它使用广播服务在重新启动后继续我的未决意图,但它没有按预期工作。重新启动手机后,我会收到弹出通知,提示MyAppsName已停止工作。我为它做的日志没有出现 manifest.xml: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.idkbro.pashchallenge"> <uses-permission android:name="an
<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>
只需在receiver类中添加以下内容:
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
Log.i("Xu", "Boot receiver is working");
}
并从清单接收者标记中删除权限和类别意图筛选器,如:
<receiver
android:name=".BootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
为什么在清单中声明两次uses权限?还有,这是什么android.intent.action.QUICKBOOT\u POWERON
?这是在HTC上吗?不是,我见过在两个不同领域使用它们的不同例子。但我不认为这就是它不起作用的原因。请附上一个实际启动接收器类的示例。您可以确认广播接收器类的完整包是com.idkbro.pashchallenge.BootReceiver
?@t0mm13b是,com.idkbro.pashchallenge.BootReceiver是。您需要通过logcat从启动中获取日志。插入电缆,重新启动手机,发出命令adb logcat
,它将等待手机启动,然后您可以捕捉到logcat的崩溃原因。非常感谢,但我得到了相同的结果。当我使用adbjava.lang.SecurityException:权限拒绝:不允许发送广播android.intent.action.BOOT_在android.os.Parcel.readException(Parcel.java:1683)的pid=13157,uid=2000中完成时,我发现了这个错误。
为什么建议OP删除权限/掌纹
<receiver
android:name=".BootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>