gpt4 book ai didi

java - AlarmManeger setExact 不起作用

转载 作者:行者123 更新时间:2023-12-01 09:16:31 26 4
gpt4 key购买 nike

setExact 方法不适用于我的项目

Log.d("Alarm","Fire");

AlarmManagerBroadcastReceiver 中的内容 1 分钟后未显示!

    public class MainActivity extends AppCompatActivity {
.
.
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.

Calendar alarm = Calendar.getInstance();
alarm.setTimeInMillis(System.currentTimeMillis());
alarm.add(Calendar.MINUTE,1);

Intent myIntent = new Intent(MainActivity.this, AlarmManagerBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarm.getTimeInMillis(), pendingIntent);
.
.
}
}

AlarmManagerBroadcastReceiver:

public class AlarmManagerBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

Log.d("Alarm","Fire");

}
}

我尝试扩展 BroadcastReceiver 而不是 WakefulBroadcastReceiver。我还尝试设置 diffrenet 硬编码时间。然而,没有任何效果。

请帮忙

最佳答案

这个link (安排重复闹钟)可以帮助您。您必须添加

<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<receiver android:process=":remote" android:name=".AlarmManagerBroadcastReceiver"></receiver>

关于java - AlarmManeger setExact 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40513296/

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