我想在应用程序中接收有关启用/禁用位置提供程序的信息,例如NETWORK
等GPS
。我创建简单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
它什么也收不到。