AlarmManager在Android上,将不会触发任何东西 [英] AlarmManager on Android won't fire anything

查看:291
本文介绍了AlarmManager在Android上,将不会触发任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使Android火灾报警在一定的时间,用户指定检查用户是否发布到服务。但是,Android将不火的意图。

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中:

AndroidManifest.xml:

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

NoBoothNotify.java功能设置报警:

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.

谁能帮助?

谢谢,

推荐答案

我似乎已经解决了这个问题。出于某种原因,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.

这篇关于AlarmManager在Android上,将不会触发任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆