0

嘿家伙希望你能帮助我。

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

    }


}
4

1 回答 1

1

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

<receiver
   android:name="AlarmReceiver"
   android:process=":remote" >
</receiver>
于 2013-03-27T10:45:11.687 回答