更新时间:2022-03-05 05:19:25
我认为您在上面的代码中的任何地方都没有调用scheduleAlarm()方法。为了即使在电话重启/关闭后仍能进行计划工作,则您必须收听 BOOT_COMPLETED 事件。对于监听引导编译,代码如下:-
I think you not called your scheduleAlarm() method any where in the code above. And for schedule work even after a phone restart/ turned off then you have to listen BOOT_COMPLETED event. For listen bootcompile the code is given below:-
您需要在清单中定义一个动作名称为 android.intent的接收器。 action.BOOT_COMPLETED 。
You need to define a receiver in manifest with action name android.intent.action.BOOT_COMPLETED.
<receiver android:name=".BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
请确保还包括完整的启动权限。
Make sure also to include the completed boot permission.
BroadcastReceiver-
BroadcastReceiver-
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
}
}