如何从应用程序 NotificationChannel >=Oreo 获取 getSound()、getName()

How to getSound(), getName() from application NotificationChannel >=Oreo

如何从特定应用程序通知渠道获取以下详细信息

我尝试使用以下代码,但它 returns 系统默认频道详细信息

 Uri=playSound ;
 String id = ApplicationClass.getInstance().HighNotificationChannelID;
 NotificationChannel mChannels = new NotificationChannel(id, getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
 playSound = mChannels.getSound();

O/P:- 内容://settings/system/notification_sound

经过多次搜索,我找到了以下方式,您可以从中获取所有详细信息。

以下 link 显示了如何以编程方式打开您的应用程序通知渠道设置。

这可能对某人有所帮助。

Following code will return you all channels of application

public static List<NotificationChannel> getNotificationChannels(Context context) {
    if (isNotificationChannelSupported(context)) {
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager == null) {
            Log.e("", "Notification manager is null");
            return null;
        }
        return notificationManager.getNotificationChannels();
    }
    return null;
}

public static boolean isNotificationChannelSupported(Context context) {
    return Build.VERSION.SDK_INT >= 26 && getTargetSdkVersion(context) >= 26;
}

private static int getTargetSdkVersion(Context context) {
    int targetSdk = -1;
    if (context != null) {
        targetSdk = context.getApplicationInfo().targetSdkVersion;
    }
    return targetSdk;
}

Following line will return you sound Uri same way you can get name,Id etc. get(2) is channel you want to refer to retrieve details you can use 0,1 also

Uri soundUri= getNotificationChannels(this).get(2).getSound()