gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:09:42 30 4
gpt4 key购买 nike

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

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

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

 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

最佳答案

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

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

open app notification setting

这可能对某人有帮助。

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()

关于android - 如何从应用程序 NotificationChannel >=Oreo 获取 getSound()、getName(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53941337/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com