How to open MIUI notifications settings?
Asked Answered
L

4

8

I'm looking for a way to open in MIUI App Notification Settings screen directly from my application. Just like this: Settings -> Installed apps -> MY_APP -> Notifications.

How to construct intent for open this screen?

That's not the same like Notification Channels Manager added in Oreo - MIUI (Xiaomi) have their own notification manager.

Legislation answered 17/9, 2018 at 16:27 Comment(7)
is the MIUI v7 or v8?Busboy
i want support for MIUI v9 and the new version 10Legislation
you'd need need to find out what the Intent is; only found these for v7 and v8. answering some other questions, in order to be able to set a bounty on this question, might be helpful.Busboy
@Legislation can you please check which of the new answers solves your problem.Kalina
@Kalina unfortunately none :(Legislation
@Legislation did you find the solution?Jurgen
Hi, did you manage to find a way and open app notification settings?Unionism
S
0

This code works in MIUI 10:

Intent settingsIntent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
                              .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                              .putExtra(Settings.EXTRA_APP_PACKAGE, "YourPackage");
                      startActivity(settingsIntent);
Swig answered 4/10, 2018 at 11:0 Comment(1)
That's androids stock notification manager. This doesn't work on MIUI - changes are not saved. MIUI have their own notification manager.Legislation
V
0
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");

//for Android 5-7
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);

// for Android O
intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());

startActivity(intent);
Venery answered 27/11, 2018 at 8:1 Comment(1)
That's androids stock notification manager. This doesn't work on MIUI.Legislation
R
0

the intents constructed to open notification settings are different on different sdk versions, you could try the code below, it runs well on my devices, assume you run this in the context of an activity:

    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //above android 8.0 jump to notification channels
    if (Build.VERSION.SDK_INT >= 26) {
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.fromParts("package", "your.package.name", null));
    }
    //android 5.0-7.0 notification settings
    if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 26) {
        intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
        intent.putExtra("app_package", "your.package.name");
        intent.putExtra("app_uid", getApplicationInfo().uid);
    }
    //others
    if (Build.VERSION.SDK_INT < 21) {
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.fromParts("package", "your.package.name", null));
    }
    startActivity(intent);
Rayleigh answered 27/11, 2018 at 15:38 Comment(1)
Your SDK >= 26 solution just opens general app settings (not notifications)Legislation
B
0

Try this

To open App Notification Settings in android Oreo and higher (MIUI v9 and 10) you need to pass NOTIFICATION_CHANNEL_ID in intent

Here is the working code tested in MIUI v9 and the new version 10

SAMPLE CODE

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.Objects;


public class MainActivity extends AppCompatActivity {

    String NOTIFICATION_CHANNEL_ID = "Nilesh_channel";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


        long pattern[] = {0, 1000, 500, 1000};

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Your Notifications",
                    NotificationManager.IMPORTANCE_HIGH);

            notificationChannel.setDescription("");
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.setVibrationPattern(pattern);
            notificationChannel.enableVibration(true);
            Objects.requireNonNull(mNotificationManager).createNotificationChannel(notificationChannel);


            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
                channel.canBypassDnd();
            }

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);

            notificationBuilder.setAutoCancel(true)
                    .setColor(ContextCompat.getColor(this, R.color.colorAccent))
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText("Test")
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.drawable.ic_launcher_background)
                    .setAutoCancel(true);


            mNotificationManager.notify(1000, notificationBuilder.build());
        }

    }

    public void ClickMe(View view) {

        notificationSettings(NOTIFICATION_CHANNEL_ID,this);
    }


    public void notificationSettings(String channel, Context context) {

        Intent intent = new Intent();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (channel != null) {
                intent.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
                intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel);
            } else {
                intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
            }
            intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());

        } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
            intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
        } else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
            intent.putExtra("app_package", context.getPackageName());
            intent.putExtra("app_uid", context.getApplicationInfo().uid);
        } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setData(Uri.parse("package:" + context.getPackageName()));
        }
        context.startActivity(intent);
    }
}
Boilermaker answered 29/11, 2018 at 4:49 Comment(1)
Your code opens some notification screen but i'm not sure what is it. This does'nt looks like screen from "Settings -> Installed apps -> MY_APP -> Notifications" where are listed all created channelsLegislation

© 2022 - 2024 — McMap. All rights reserved.