我一直在尝试使用AlarmManager.RTC_WAKEUP来唤醒我的设备来播放一些声音。 这里的报警调度:AlarmManager.RTC_WAKEUP没有唤醒设备?
Intent intent = new Intent(Main.this, OneShotAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(Main.this, 0, intent, 0);
// I want the alarm to go off 60 seconds from now.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 60);
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), sender);
的OneShotAlarm广播接收器:
public class OneShotAlarm extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "OneShotAlarm Broadcast invoked", 1000).show();
intent = new Intent(context, ServiceClassToRun.class);
context.startService(intent);
}
}
的服务:
public class ServiceClassToRun extends Service {
protected static final int Rnd = 0;
public void onStart(Intent intent, int startId) {
//do some business here
}
最后,我的表现:当设备处于唤醒状态
<receiver android:name=".OneShotAlarm" android:process=":remote" />
<service android:name=".ServiceClassToRun "/>
我的服务工作正常。 任何想法,不胜感激。有没有其他人经历过这样的 ?提前致谢。
你有写的所有权限的例子吗? –