2016-11-30 23 views
0

我有一个应用程序,使用广播服务来重新启动后继续我的未决意图,但它没有按照它应有的工作。在我重新启动手机后,我弹出通知MyAppsName has stopped working。我为它制作的日志没有出现。Android:引导广播重新启动后不工作

的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

为什么在清单中声明了两次权限?这是什么'android.intent.action.QUICKBOOT_POWERON'?这是在HTC吗? – t0mm13b

+0

不是我见过不同的例子,使用它们在2个不同的领域。但我不认为这就是为什么它不起作用 –

+1

请附上一个实际启动接收器类的[MCVE]示例。你可以确认广播接收器类的完整包是'com.idkbro.pashchallenge.BootReceiver'? – t0mm13b

回答

-1

就在接收器类补充一点:

if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){ 
    Log.i("Xu", "Boot receiver is working"); 
} 

和删除权限和类别意图从清单reciver标记中过滤掉,例如:

<receiver 
     android:name=".BootReceiver" 
     android:enabled="true"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 

     </intent-filter> 
    </receiver> 
+0

非常感谢,但我得到了同样的结果。我得到这个错误,当我检查它使用adb'java.lang.SecurityException:权限拒绝:不允许发送广播android.intent.action.BOOT_COMPLETED从pid = 13157,uid = 2000 at android.os.Parcel.readException (Parcel.java:1683)' –

+0

你为什么建议OP删除权限? /捂脸 – t0mm13b