zoukankan      html  css  js  c++  java
  • android app通知栏权限状态判断及跳转状态栏设置页面

    import android.app.NotificationManager;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Build;
    import android.provider.Settings;
    import android.support.v4.app.NotificationManagerCompat;
    
    /**
     * Created by chenxiangxiang on 2019/1/16.
     */
    
    public class Utils {
    
        public static boolean isPermissionOpen(Context context) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                return NotificationManagerCompat.from(context).getImportance() != NotificationManager.IMPORTANCE_NONE;
            }
            return NotificationManagerCompat.from(context).areNotificationsEnabled();
        }
    
        public static void openPermissionSetting(Context context) {
            try {
                Intent localIntent = new Intent();
                localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //直接跳转到应用通知设置的代码:
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    localIntent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
                    localIntent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
                    context.startActivity(localIntent);
                    return;
                }
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    localIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                    localIntent.putExtra("app_package", context.getPackageName());
                    localIntent.putExtra("app_uid", context.getApplicationInfo().uid);
                    context.startActivity(localIntent);
                    return;
                }
                if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
                    localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    localIntent.addCategory(Intent.CATEGORY_DEFAULT);
                    localIntent.setData(Uri.parse("package:" + context.getPackageName()));
                    context.startActivity(localIntent);
                    return;
                }
    
                //4.4以下没有从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面,
    
                if (Build.VERSION.SDK_INT >= 9) {
                    localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                    localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
                    context.startActivity(localIntent);
                    return;
                }
    
                localIntent.setAction(Intent.ACTION_VIEW);
                localIntent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails");
                localIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
    
    
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println(" cxx   pushPermission 有问题");
            }
        }
    }
  • 相关阅读:
    策略模式
    Properties类学习笔记
    System类学习笔记
    一个反射的妙用案例
    new 对象时的暗执行顺序
    常用数据库默认端口号
    java对日开发常用语(词汇)总结
    java开发中常用语(词汇)含义
    MyBatis 常用词汇含义
    java SE,EE,ME区别
  • 原文地址:https://www.cnblogs.com/shoneworn/p/10276980.html
Copyright © 2011-2022 走看看