我写了下面的代码,但它不起作用。有谁能够帮助我?我只想被动接收GPS状态变化,而不是主动查询。省电最重要。
没有消息输出。
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();
}
}
}
这是我的 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>