android alarmmanager广播接收器未被调用

时间:2013-03-27 10:40:28

标签: android android-alarms android-broadcast android-pendingintent

嘿伙计们希望你能帮助我。

我是第一次使用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();

    }


}

1 个答案:

答案 0 :(得分:1)

您是否在清单中添加了以下代码?

<receiver
   android:name="AlarmReceiver"
   android:process=":remote" >
</receiver>