简体   繁体   English

Android上的AlarmManager不会触发任何操作

[英]AlarmManager on Android won't fire anything

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. 我正在尝试让Android在用户指定的某个时间触发警报,以检查用户是否已发布到服务。 However, Android won't fire the intent. 但是,Android不会激发意图。

AndroidManifest.xml: 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: 设置警报的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);
    }
}

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

I seem to have fixed this. 我似乎已经解决了这个问题。 For some reason Android doesn't like to fire Alarms if the receiver is a subclass. 由于某些原因,如果接收方是子类,则Android不希望触发Alarms。

To fix and keep origination, I moved it all to a new namespace and it worked. 为了修复并保持原始,我将其全部移到了新的命名空间中并成功运行。

Joe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM