Android 8.0 跳转通知设置界面适配

注意:锤子、小米需要特殊处理下
public static void toOpenNotification(Context context) {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Smartisan
    try {
        if (OSUtils.isSmartisan()) {
            intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
            intent.setData(Uri.fromParts("package", BuildConfig.APP_PACKAGE_NAME, null));
        } else {
            if (Build.VERSION.SDK_INT >= 26) {
                // android 8.0引导
                intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                intent.putExtra("android.provider.extra.APP_PACKAGE", BuildConfig.APP_PACKAGE_NAME);
            } else if (Build.VERSION.SDK_INT >= 21) {
                // android 5.0-7.0
                intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                intent.putExtra("app_package", BuildConfig.APP_PACKAGE_NAME);
                intent.putExtra("app_uid", context.getApplicationInfo().uid);
            } else {
                // 其他
                intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                intent.setData(Uri.fromParts("package", BuildConfig.APP_PACKAGE_NAME, null));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        //锤子手机没有通知设置界面》》https://www.jianshu.com/p/1e27efb1dcac
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.fromParts("package", BuildConfig.APP_PACKAGE_NAME, null));
    }
    context.startActivity(intent);
}

Thanks:https://www.jianshu.com/p/1e27efb1dcac

 

你可能感兴趣的:(Android,适配方案)