Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZouZLong opened this issue Nov 3, 2023 · 2 comments
Open

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

ZouZLong opened this issue Nov 3, 2023 · 2 comments

Comments

@ZouZLong
Copy link

ZouZLong commented Nov 3, 2023

No description provided.

@ZouZLong
Copy link
Author

ZouZLong commented Nov 3, 2023

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
Copy link

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);
    }

}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants