如何从报警管理器获取报警ID
问题描述:
我正在创建一个剩余应用程序,它在指定的时间开始报警并重复直到用户停止它。如何从报警管理器获取报警ID
我生成一个唯一的号码,并把它传递给我的AlarmManager类,
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), remainderID.intValue(), intent, 0);
// remainderID is unqiue value, generated from Database.
我知道取消报警的步骤,但我无法理解如何在广播接收机类得到这个ID。
请亲引导我。
答
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), remainderID.intValue(), intent, 0);
加入您的专属代码和任何其他数据,你需要对上面的意图,并提取下面AlarmService类相同的目的。
public class AlarmService extends IntentService {
@Override
public void onHandleIntent(Intent intent) {
if (intent == null) return;
try
{
// send the intent to your AlarmManager class and process it there.
YourAlarmManager.processAlarm(intent, this);
} catch (Exception e){
e.printStackTrace();
}
}
}
希望这会有所帮助! :)