1

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

  • 获取声音();获取名称();获取标识();获取组();

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

 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:- content://settings/system/notification_sound

4

1 回答 1

0

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

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

打开应用通知设置

这可能会帮助某人。

以下代码将返回您申请的所有渠道

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;
}

以下行将以相同的方式返回您的声音Uri,您可以获得名称、ID 等。 get(2)是您想要参考的频道检索详细信息,您也可以使用 0,1

Uri soundUri= getNotificationChannels(this).get(2).getSound()
于 2018-12-27T08:18:34.930 回答