我对BootBroadcastReceiver
Permission taken in manifest :<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
BootBroadcastReceiver
的清单中的意图过滤器:
<receiver android:name=".receivers.BootBroadcastReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE"/>
</intent-filter>
</receiver>
其他操作是某些线程在线阅读的结果。
以下是实施类:
public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Application boot event");
Toast.makeText(context, "Boot completed", Toast.LENGTH_SHORT).show();
}
}
但是不知何故在重启或开机时我无法完成启动,我也添加了吐司。没有吐司。
也有人建议仅在内部存储器上安装应用程序,因为启动完成广播不会传送到外部存储上的应用程序。通过在清单android:installLocation="internalOnly"
中设置标志,我也做了这个,但对我没用。可能有什么问题?
用于测试的设备:
Moto E3 power (Android 6.0 ), Lenovo A6020a40 ( Android 5.1.1)
答案 0 :(得分:0)
使用此代码
public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Log.d("startuptest", "StartUpBootReceiver BOOT_COMPLETED");
Toast.makeText(context, "Boot completed", Toast.LENGTH_SHORT).show();
}
}
}
也在清单文件接收器中定义,如此
<receiver android:name="com.example.startuptest.StartUpBootReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>