我到处都是类似的问题,但是由于某种原因,我的BroadcastReceiver从未收到过android.intent.action.BOOT_COMPLETED Intent。
这是我的(相对)Android.Manifest文件:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<receiver android:name=".BootReceiver"
android:enabled="true"
android:exported="true"
android:label="BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
这是实际的接收方。
public class BootReceiver extends BroadcastReceiver {
private static final String TAG="BootReceiver";
@Override public void onReceive(Context context,Intent intent){
try{
context.startService(new Intent(context,ConnectivityListener.class));
Log.i(TAG,"Starting Service ConnectivityListener");
}catch(Exception e){
Log.e(TAG,e.toString());
}
}
}
谢谢!任何帮助是极大的赞赏