0

嗨希望你能幫助我。安卓alarmmanager廣播reciever不會被調用

我使用alarmManager首次新手anodroid開發商,但廣播接收機dosent似乎被調用。

繼承人創建該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); 

和廣播reciever類

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

你在你的清單中添加以下代碼的代碼?

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

Urggh ..總是忘記更新清單。謝謝。 – 2013-03-27 11:00:57

+0

它發生在我身上了很多;) 不客氣。 – 2013-03-27 11:04:29

+1

你不會需要「:遠程」,因爲它不是在一個單獨的進程需要。此外,我會建議使用的名稱「.AlarmReceiver」(注意點),因此接收器的命名空間是一樣的包。 – RvdK 2013-03-27 12:15:04