大家好,
我想在MainActivity中使用AlarmManager固定做一些事情,
但BroadcastReceiver卻始終不被觸發,
請教一下高手.
程式碼如下:
MainActivity.class
public class MainActivity extends Activity {
private class loginHttp extends AsyncTask<String, Integer, String>{
//使用HTTP進行身分認證動作(非同步)
@Override
protected void onPostExecute(String result) {
//登入成功後開始回傳GPS定位資料
AlarmManager alarmmanager = (AlarmManager)
getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent gpsintent =new Intent(getApplicationContext(),
gps_sendback_alarm_receiver.class);
PendingIntent pendingIntent =
PendingIntent.getBroadcast(getApplicationContext(),
UUID.randomUUID().hashCode(), gpsintent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmmanager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
System.currentTimeMillis(), int_gps_sendback_period, pendingIntent);
}}}
gps_sendback_alarm_receiver.class
public class gps_sendback_alarm_receiver extends BroadcastReceiver implements
LocationListener{
public void onReceive(Context context, Intent intent) {
//處理回傳GPS的作業
Log.d("gps_sendback", "gps_sendback_alarm_receiver.onReceive()");
}}
AndroidManifest.xml
<receiver android:name=".gps_sendback_alarm_receiver"
android:process=":remote" android:enabled="true"/>
問題在於
Log.d("gps_sendback", "gps_sendback_alarm_receiver.onReceive()");
始終不會被觸發,
請高手幫忙,
謝謝~