gpt4 book ai didi

java - BroadcastReceiver 没有收到任何内容

转载 作者:行者123 更新时间:2023-12-02 06:51:00 28 4
gpt4 key购买 nike

我想在应用程序中接收有关启用/禁用位置提供程序的信息,例如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 没有接收到任何内容。

最佳答案

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

<receiver android:name=".receiver.TestReciver"> 
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
</intent-filter>
</receiver>

关于java - BroadcastReceiver 没有收到任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18032251/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com