gpt4 book ai didi

Android alarmManager 设置重复不触发

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:52:39 25 4
gpt4 key购买 nike

我正在尝试在指定时间设置闹钟,但它没有被我的接收器捕捉到。

设置:

Intent intent = new Intent(this, ActionReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

Calendar current = Calendar.getInstance();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, (current.getTimeInMillis() + 60000),3600000, pendingIntent);

这是我的接收器:

public class ActionReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras(); //breakpoint here that doesn't get triggered
}
}

我已将这些值放入我的 list 中:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<receiver android:name="com.project.ActionReceiver" android:enabled="true" />

不确定哪里出了问题...谢谢!

最佳答案

终于让接收器开火了!我将以下代码添加到我的 list 中:

    <receiver
android:name="com.project.ActionReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.project.ActionSetter" >
</action>
</intent-filter>
</receiver>

在此处找到详细信息:https://stackoverflow.com/a/16119351/1174574

关于Android alarmManager 设置重复不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18626996/

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