0

我想在应用程序中接收有关启用/禁用位置提供程序的信息,例如NETWORKGPS。我创建简单BroadcastReceiver

public class TestReciver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {

        Log.v("LOCATION_CHANGE_RECEIVER", "PROVIDER UPDATE");
    }
}

并将其注册到AndroidManifest.xml

  <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
      <application
                android:label="@string/app_name"
                android:icon="@drawable/ic_launcher"
                android:allowBackup="true"
                android:debuggable="true">
        <receiver android:name=".receiver.TestReciver">
            <intent-filter>
                <action android:name="android.intent.action.PROVIDER_CHANGED"/>
            </intent-filter>
        </receiver>

但是当我尝试打开/关闭 GPS 时,BroadcastReceiver它什么也收不到。

4

1 回答 1

2

将您的意图过滤器更改为android.location.PROVIDERS_CHANGED

<receiver android:name=".receiver.TestReciver"> 
    <intent-filter> 
        <action android:name="android.location.PROVIDERS_CHANGED" /> 
    </intent-filter> 
</receiver>
于 2013-08-03T11:23:07.587 回答