Android 上的 AlarmManager 不会触发任何东西

发布于 2024-11-07 10:23:58 字数 1820 浏览 3 评论 0原文

我试图让 Android 在用户指定的某个时间触发警报,以检查用户是否已发布到该服务。但是,Android 不会触发该意图。

AndroidManifest.xml:

<receiver
 android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmReciever" />
<service
 android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmService">
</service>

设置警报的 NoBoothNotify.java 函数:

public static void settingsChanged(){
    Context cntxt = DailyboothApplication.getInstance();
    String value = DailyboothShared.getPersonalSetting("noBoothNotify", "no");
    AlarmManager alm = (AlarmManager) cntxt.getSystemService(Context.ALARM_SERVICE);

    Intent piI = new Intent(cntxt, AlarmReciever.class);
    if(Build.VERSION.SDK_INT >= 5){
        SharedPreferences prefs = DailyboothShared.getPrefs();
        piI.putExtra("account", prefs.getString("current_account", null));
    }
    PendingIntent pi = PendingIntent.getBroadcast(cntxt, 348347873, piI, PendingIntent.FLAG_UPDATE_CURRENT);

    if(value.equals("no")){
        alm.cancel(pi);
    } else{
        String[] values = value.split(":");
        Calendar cal = Calendar.getInstance();
        Log.d("s", value);
        // cal.setTimeInMillis(System.currentTimeMillis());
        cal.clear(Calendar.HOUR_OF_DAY);
        cal.clear(Calendar.SECOND);
        cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(values[0]));
        cal.set(Calendar.MINUTE, Integer.parseInt(values[1]));
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        Log.d("s", "setting for " + cal.getTimeInMillis());
        Log.d("s", "HRD: " + cal.getTime().toGMTString());
        alm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                /*AlarmManager.INTERVAL_DAY,*/ pi);
    }
}

如您所见,我正在尝试使其正常工作(因此被注释掉的部分),但是它仍然无法正常工作。

有人可以帮忙吗?

谢谢,

I'm trying to make Android fire a Alarm at a certain time the user specifies to check if the user has posted to the service. However, Android won't fire the intent.

AndroidManifest.xml:

<receiver
 android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmReciever" />
<service
 android:name="me.kennydude.dailybooth.NoBoothNotify.AlarmService">
</service>

NoBoothNotify.java function that sets the alarm:

public static void settingsChanged(){
    Context cntxt = DailyboothApplication.getInstance();
    String value = DailyboothShared.getPersonalSetting("noBoothNotify", "no");
    AlarmManager alm = (AlarmManager) cntxt.getSystemService(Context.ALARM_SERVICE);

    Intent piI = new Intent(cntxt, AlarmReciever.class);
    if(Build.VERSION.SDK_INT >= 5){
        SharedPreferences prefs = DailyboothShared.getPrefs();
        piI.putExtra("account", prefs.getString("current_account", null));
    }
    PendingIntent pi = PendingIntent.getBroadcast(cntxt, 348347873, piI, PendingIntent.FLAG_UPDATE_CURRENT);

    if(value.equals("no")){
        alm.cancel(pi);
    } else{
        String[] values = value.split(":");
        Calendar cal = Calendar.getInstance();
        Log.d("s", value);
        // cal.setTimeInMillis(System.currentTimeMillis());
        cal.clear(Calendar.HOUR_OF_DAY);
        cal.clear(Calendar.SECOND);
        cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(values[0]));
        cal.set(Calendar.MINUTE, Integer.parseInt(values[1]));
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        Log.d("s", "setting for " + cal.getTimeInMillis());
        Log.d("s", "HRD: " + cal.getTime().toGMTString());
        alm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                /*AlarmManager.INTERVAL_DAY,*/ pi);
    }
}

As you can see I'm trying to just get it working one (hence the commented out part), however it doesn't work still.

Can anyone help?

Thanks,

Joe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮云壑 2024-11-14 10:23:58

我似乎已经解决了这个问题。由于某种原因,如果接收者是子类,Android 不喜欢触发警报。

为了修复并保持起源,我将其全部移动到一个新的命名空间并且它起作用了。

I seem to have fixed this. For some reason Android doesn't like to fire Alarms if the receiver is a subclass.

To fix and keep origination, I moved it all to a new namespace and it worked.

Joe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文