2013-01-11 12 views
0

使用下面的代碼廣播服務沒有得到所謂的

Intent i = new Intent(this, BootUpReceiverRecall.class); 
     sendBroadcast(i); 

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


public class BootUpReceiverRecall extends BroadcastReceiver 
{ 
     // Restart service every 30 seconds 
     private static final long REPEAT_TIME = 1000 * 30; 

     @Override 
     public void onReceive(Context context, Intent intent) 
     { 
     AlarmManager service = (AlarmManager) context 
      .getSystemService(Context.ALARM_SERVICE); 
     Intent i = new Intent(context, BootUpReceiver.class); 
     PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, 
      PendingIntent.FLAG_CANCEL_CURRENT); 
     Calendar cal = Calendar.getInstance(); 
     // Start 30 seconds after boot completed 
     cal.add(Calendar.SECOND, 30); 
     // 
     // Fetch every 30 seconds 
     // InexactRepeating allows Android to optimize the energy consumption 
     service.setInexactRepeating(AlarmManager.RTC_WAKEUP, 
      cal.getTimeInMillis(), REPEAT_TIME, pending); 

     // service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 
     // REPEAT_TIME, pending); 
     } 

我BootUpReceiver不會被調用。我在做什麼錯 ?

回答

1

您需要在AndroidManifest.xml正確地定義它:

<receiver 
android:process=":remote" 
android:name=".BootUpReceiverRecall" /> 

在「安卓名」看看標籤,
你需要前添加一個點(」。‘)的’ BootUpReceiverRecall「,如果它與應用程序位於同一個包中,但如果不是,則可以簡單地使用」app.package.receivers.BootUpReceiverRecall「等全名。