我使用按钮点击使用报警管理器启动服务。它也在工作。我这样做:通过广播接收机自动启动服务
Intent scheduleSMS = new Intent(SMSProjectDatabase.this,SendSMS.class);
PendingIntent pendingIntent = PendingIntent.getService(SMSProjectDatabase.this,0, scheduleSMS,0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND,(int)GeneralUtil.calculateTimeDifference(getApplicationContext()));
Log.i("SMS is scheduled after ",""+GeneralUtil.calculateTimeDifference(getApplicationContext()));
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
这里SendSMS是一个服务,将由警报管理器启动。但这不是我想要在我的代码中启动服务的方式。我想使用Alarmmanager为Broadcastreceiver触发广播。 Broadcastreceiver然后为我启动服务。
我的广播接收装置,
公共类MyReceiver扩展广播接收器{
@Override
public void onReceive(Context context, Intent intent) {
//here i want to start the service through the alarm manager
}
}
但我唐诺我应该怎么办this.Please提供相应的解决方案为我解决这个问题。