dingjikerbo / Android-BluetoothKit

Android BLE蓝牙通信库
Apache License 2.0
3.59k stars 738 forks source link

我已经适配好了Android 12~14 #186

Open ZouZLong opened 1 year ago

ZouZLong commented 1 year ago

private static void registerGlobalReceiver(BroadcastReceiver receiver, IntentFilter filter) { try { LogUtil.loge("666", "Build.VERSION.SDK_INT:" + Build.VERSION.SDK_INT);//34 LogUtil.loge("666", "Build.VERSION_CODES.O:" + Build.VERSION_CODES.O);//26 LogUtil.loge("666", "Build.VERSION_CODES.TIRAMISU:" + Build.VERSION_CODES.TIRAMISU);//33

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                getContext().registerReceiver(receiver, filter, RECEIVER_EXPORTED);
            } else getContext().registerReceiver(receiver, filter);
        } else getContext().registerReceiver(receiver, filter);
    } catch (Exception e) {
        LogUtil.loge("registerGlobalReceiver:" + e);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
            getContext().registerReceiver(receiver, filter, RECEIVER_EXPORTED);
        else getContext().registerReceiver(receiver, filter);
    }

}

修改为这样的代码就可以了

qwuip789 commented 5 months ago

private static void registerGlobalReceiver(BroadcastReceiver receiver, IntentFilter filter) { try { LogUtil.loge("666", "Build.VERSION.SDK_INT:" + Build.VERSION.SDK_INT);//34 LogUtil.loge("666", "Build.VERSION_CODES.O:" + Build.VERSION_CODES.O);//26 LogUtil.loge("666", "Build.VERSION_CODES.TIRAMISU:" + Build.VERSION_CODES.TIRAMISU);//33

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                getContext().registerReceiver(receiver, filter, RECEIVER_EXPORTED);
            } else getContext().registerReceiver(receiver, filter);
        } else getContext().registerReceiver(receiver, filter);
    } catch (Exception e) {
        LogUtil.loge("registerGlobalReceiver:" + e);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
            getContext().registerReceiver(receiver, filter, RECEIVER_EXPORTED);
        else getContext().registerReceiver(receiver, filter);
    }

}

修改为这样的代码就可以了 能够说下你怎么适配的吗?