アプリの通知がブロックされているかどうかを確認し、リマインダーをポップアップして、対応する開いている通知ページにジャンプするボタンを提供します

要求する:

1.新規またはアップグレードされたインストール後、システムがアプリの通知をブロックするかどうかを確認します。

2.通知がブロックされている場合、通知を開くように通知するポップアップウィンドウがポップアップ表示されます。

3.ポップアップウィンドウの[今すぐ開く]ボタンをクリックして、システムに対応するこのアプリの通知設定インターフェイスにジャンプします。

解決:

1.通知アプリの通知機能がブロックされているかどうかを確認します。コードは次のように表示されます。

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();

注:この方法はAndroid4.3以降のみを対象としています

2.対応する通知設定ページにジャンプします。コードは次のように表示されます。

public static void goSystemNotificationSetting(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            Uri uri = Uri.parse("package:" + context.getPackageName());
            Intent intentSet = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
            context.startActivity(intentSet);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Intent intent = new Intent();
            intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
            intent.putExtra("app_package", context.getPackageName());
            intent.putExtra("app_uid", context.getApplicationInfo().uid);
            context.startActivity(intent);
        } 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:" + context.getPackageName()));
            context.startActivity(intent);
        } else {

            Intent localIntent = new Intent();
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
            context.startActivity(localIntent);
        }
    }

 

 

おすすめ

転載: blog.csdn.net/nsacer/article/details/80350735