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 有问题");
            }
        }
    }
  • 相关阅读:
    前端 fetch 通信
    编写高质量的JavaScript代码(一)
    Redis学习笔记1-Redis的介绍和认识
    gitignore不起作用解决的方法
    【我的面经】说说简历的细节——软件开发岗位
    菜鸟的mongoDB学习---(七)MongoDB 备份(mongodump)与恢复(mongorerstore)
    HDU 4927 Series 1
    树状数组求第K小值 (spoj227 Ordering the Soldiers && hdu2852 KiKi's K-Number)
    git和SVN的差别
    KVM-Introduce
  • 原文地址:https://www.cnblogs.com/shoneworn/p/10276980.html
Copyright © 2011-2022 走看看