android-BOOT_COMPLETED没有在设备中被调用
作者:互联网
我想在设备启动时启动警报,为此我已经完成了以下工作
1)用户权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2)在清单文件中添加具有意图动作的接收器
<receiver
android:name=".sms.BootReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
3)来源
public class BootReceiver extends BroadcastReceiver {
private AlarmManager dayAlarmMgr;
private PendingIntent dayAlarmIntent;
private NotificationManager mNotificationManager;
private NotificationCompat.Builder builder;
private Context context;
public static final int NOTIFICATION_ID = 2;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Toast.makeText(context, "FIRED BOOT COMPLETE" , Toast.LENGTH_LONG).show();
}
}
}
上面的代码在genymotion中起作用,但在实际设备上不起作用
解决方法:
感谢您的帮助,但最终我能够通过将android:installLocation =“ internalOnly”设置为android.intent.action.BOOT_COMPLETED来使其工作,因为它们完全存储在内部存储器中.
标签:android-broadcast,android,android-reboot 来源: https://codeday.me/bug/20191120/2046877.html