嘿家伙希望你能帮助我。
我是第一次使用 alarmManager 的新手 anodroid 开发人员,但广播接收器似乎被调用了。
这是创建alarmManager的代码
AlarmManager alarm=(AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(this,AlarmReciever.class);
PendingIntent p=PendingIntent.getBroadcast(this, 22, i,PendingIntent.FLAG_CANCEL_CURRENT);
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,1,p);
和广播接收器类
Public class AlarmReciever extends BroadcastReceiver{
@Override
public void onReceive(Context c, Intent i) {
// TODO Auto-generated method stub
Toast toast1= Toast.makeText(c, "This text will be displayed \n on the toast", Toast.LENGTH_LONG);
toast1.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
toast1.show();
}
}