我正在做一个 android 计划应用程序,我使用 AlarmManager,但我的闹钟不起作用,这是我的代码:
我的活动:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR, 1);
calendar.set(Calendar.SECOND, 44);
calendar.set(Calendar.AM_PM, Calendar.PM);
pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, MyBroadCastRcv.class), 0);
getApplicationContext();
AlarmManager alarmMngr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmMngr.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
MyBroadCastRcv 类:
public void onReceive(Context context, Intent intent)
{
Intent serviceLauncher = new Intent(context, TimerService.class);
context.startService(serviceLauncher);
}
我的服务:
public int onStartCommand(Intent intent, int flags, int startId)
{
super.onCreate();
MediaPlayer player = MediaPlayer.create(this, Uri.parse("file:///mnt/sdcard/sherif/001.mp3"));
return super.onStartCommand(intent, flags, startId);
}
public void onStart(Intent intent, int startId)
{
System.out.println("In onStart Service");
super.onStart(intent, startId);
player.start();
}
我错过了什么吗?