相关疑难解决方法(0)

关闭GPS时,广播接收机被叫2次?

表现:

<receiver android:name=".GpsLocationReceiver">
    <intent-filter>
        <action android:name="android.location.PROVIDERS_CHANGED" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

BroadcastReceiver:

public class GpsLocationReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive...");
        if(intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
            Log.d(TAG, "GPS provider changed...");
            EventBus.getDefault().postLocal(intent.getAction());
        }
    }

}:
Run Code Online (Sandbox Code Playgroud)

android android-broadcast

5
推荐指数
1
解决办法
1128
查看次数

标签 统计

android ×1

android-broadcast ×1