我需要在系统重新启动而不是在启动完成时将数据写入文件中。
我正在使用广播接收器“ android.intent.action.REBOOT”,下面是我的代码和清单文件
public class broadcastreceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Log.i("LOG_TAG","rebooted");
}
清单文件:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".broadcast"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.broadcastreceiver.broadcastreceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.REBOOT">
<intent-filter>
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
</application>
但重启后我什至不能写日志。
注意:我不想在广播接收器中使用Bootcompleted操作
最佳答案
我看不到您为什么不想使用BootCompleted,您能提供原因吗?
没有其他动作可以警告您的广播接收器启动。您将必须使用BootCompleted。
需要注意的是,我希望您在上下文中注册了BroadcastReceiver(因为您未包含该代码)。如果您没有使用BootComplete,则我不知道您已经注册了什么操作来期望您的上述代码执行。