gpt4 book ai didi

android - 重启时广播接收器?

转载 作者:行者123 更新时间:2023-11-29 00:43:49 25 4
gpt4 key购买 nike

我需要将数据写入文件,当系统重新启动时未完成启动。我正在使用广播接收器“android.intent.action.REBOOT” 下面是我的代码和 list 文件

public class broadcastreceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Log.i("LOG_TAG","rebooted");
}

list 文件:

<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,我不知道您注册了什么操作来期望您的上述代码执行。

关于android - 重启时广播接收器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com