Showing
2 changed files
with
68 additions
and
7 deletions
| @@ -17,6 +17,7 @@ import com.mixpush.huawei.HuaweiPushProvider.HUAWEI | @@ -17,6 +17,7 @@ import com.mixpush.huawei.HuaweiPushProvider.HUAWEI | ||
| 17 | import com.ewin.flutter_push.EwinMixPushReceiver | 17 | import com.ewin.flutter_push.EwinMixPushReceiver |
| 18 | import com.ewin.flutter_push.enums.MixListenerTypeEnum | 18 | import com.ewin.flutter_push.enums.MixListenerTypeEnum |
| 19 | import com.ewin.flutter_push.utils.CommonUtil | 19 | import com.ewin.flutter_push.utils.CommonUtil |
| 20 | +import com.ewin.flutter_push.utils.NotificationManagerUtils | ||
| 20 | import com.alibaba.fastjson.JSON | 21 | import com.alibaba.fastjson.JSON |
| 21 | import com.mixpush.core.MixPushMessage | 22 | import com.mixpush.core.MixPushMessage |
| 22 | import android.content.ComponentName; | 23 | import android.content.ComponentName; |
| @@ -76,15 +77,10 @@ class FlutterPushPlugin: FlutterPlugin, MethodCallHandler { | @@ -76,15 +77,10 @@ class FlutterPushPlugin: FlutterPlugin, MethodCallHandler { | ||
| 76 | }) | 77 | }) |
| 77 | result.success(true) | 78 | result.success(true) |
| 78 | } else if(call.method == "checkPermission") { | 79 | } else if(call.method == "checkPermission") { |
| 79 | - result.success(NotificationManagerCompat.from(context).areNotificationsEnabled()) | 80 | + result.success(NotificationManagerUtils.isPermissionOpen(context)) |
| 80 | } else if(call.method == "getPermission") { | 81 | } else if(call.method == "getPermission") { |
| 81 | CommonUtil.runMainThread { | 82 | CommonUtil.runMainThread { |
| 82 | - val intent = Intent().apply { | ||
| 83 | - action = Settings.ACTION_APP_NOTIFICATION_SETTINGS | ||
| 84 | - putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) | ||
| 85 | - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
| 86 | - } | ||
| 87 | - context.startActivity(intent) | 83 | + NotificationManagerUtils.openPermissionSetting(context) |
| 88 | } | 84 | } |
| 89 | result.success(true) | 85 | result.success(true) |
| 90 | } else { | 86 | } else { |
| 1 | +package com.ewin.flutter_push.utils; | ||
| 2 | + | ||
| 3 | +import android.app.NotificationManager; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.Intent; | ||
| 6 | +import android.net.Uri; | ||
| 7 | +import android.os.Build; | ||
| 8 | +import android.provider.Settings; | ||
| 9 | + | ||
| 10 | +import androidx.core.app.NotificationManagerCompat; | ||
| 11 | + | ||
| 12 | +public class NotificationManagerUtils { | ||
| 13 | + | ||
| 14 | + public static boolean isPermissionOpen(Context context) { | ||
| 15 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
| 16 | + return NotificationManagerCompat.from(context).getImportance() != NotificationManager.IMPORTANCE_NONE; | ||
| 17 | + } | ||
| 18 | + return NotificationManagerCompat.from(context).areNotificationsEnabled(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public static void openPermissionSetting(Context context) { | ||
| 22 | + try { | ||
| 23 | + Intent localIntent = new Intent(); | ||
| 24 | + localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| 25 | + //直接跳转到应用通知设置的代码: | ||
| 26 | + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
| 27 | + localIntent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS); | ||
| 28 | + localIntent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); | ||
| 29 | + context.startActivity(localIntent); | ||
| 30 | + return; | ||
| 31 | + } | ||
| 32 | + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| 33 | + localIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); | ||
| 34 | + localIntent.putExtra("app_package", context.getPackageName()); | ||
| 35 | + localIntent.putExtra("app_uid", context.getApplicationInfo().uid); | ||
| 36 | + context.startActivity(localIntent); | ||
| 37 | + return; | ||
| 38 | + } | ||
| 39 | + if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { | ||
| 40 | + localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | ||
| 41 | + localIntent.addCategory(Intent.CATEGORY_DEFAULT); | ||
| 42 | + localIntent.setData(Uri.parse("package:" + context.getPackageName())); | ||
| 43 | + context.startActivity(localIntent); | ||
| 44 | + return; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + //4.4以下没有从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面, | ||
| 48 | + | ||
| 49 | + if (Build.VERSION.SDK_INT >= 9) { | ||
| 50 | + localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); | ||
| 51 | + localIntent.setData(Uri.fromParts("package", context.getPackageName(), null)); | ||
| 52 | + context.startActivity(localIntent); | ||
| 53 | + return; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + localIntent.setAction(Intent.ACTION_VIEW); | ||
| 57 | + localIntent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails"); | ||
| 58 | + localIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName()); | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + } catch (Exception e) { | ||
| 62 | + e.printStackTrace(); | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | +} |
-
Please register or login to post a comment