I wrote the code below, but it's not working. Can anybody help me? I just want to passively receiving GPS status changes, rather than proactive inquiries. Saving power is most important.
There is no message output.
package com.sharelbs.lbs.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class GPStStatusReceiver extends BroadcastReceiver {
public static final String GPS_ENABLED_CHANGE_ACTION = "android.location.GPS_ENABLED_CHANGE";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("---------log--------","GPS Status onReceive");
if(intent.getAction().equals(GPS_ENABLED_CHANGE_ACTION)){
Log.d("---------log--------","GPS Status Changed");
startMyProgram();
}
}
}
Here is my Manifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<receiver android:name=".service.GPStStatusReceiver">
<intent-filter>
<action android:name="android.location.GPS_ENABLED_CHANGE" />
</intent-filter>
</receiver>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…