短视频程序源码,通知权限问题,及禁止不再弹出问题

if(!NotificationManagerCompat.from(context).areNotificationsEnabled()){
     
gotoNotificationSetting();
}
public void gotoNotificationSetting() {
     
        ApplicationInfo appInfo = activity.getApplicationInfo();
        String pkg = activity.getApplicationContext().getPackageName();
        int uid = appInfo.uid;
        try {
     
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     
                Intent intent = new Intent();
                intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
                //这种方案适用于 API 26, 即8.0(含8.0)以上可以用
                intent.putExtra(Settings.EXTRA_APP_PACKAGE, pkg);
                intent.putExtra(Settings.EXTRA_CHANNEL_ID, uid);
                //这种方案适用于 API21——25,即 5.0——7.1 之间的版本可以使用
                intent.putExtra("app_package", pkg);
                intent.putExtra("app_uid", uid);
                this.startActivityForResult(intent, REQUEST_SETTING_NOTIFICATION);
            } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
     
                Intent intent = new Intent();
                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.addCategory(Intent.CATEGORY_DEFAULT);
                intent.setData(Uri.parse("package:" + getPackageName()));
                this.startActivityForResult(intent, REQUEST_SETTING_NOTIFICATION);
            } else {
     
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                this.startActivityForResult(intent, REQUEST_SETTING_NOTIFICATION);
            }
        } catch (Exception e) {
     
            Intent intent = new Intent(Settings.ACTION_SETTINGS);
            this.startActivityForResult(intent, REQUEST_SETTING_NOTIFICATION);
        }
    }

你可能感兴趣的:(技术类,android,办公软件,openjdk,安卓,gradle)