【问题标题】:How to getSound(), getName() from application NotificationChannel >=Oreo如何从应用程序 NotificationChannel >=Oreo 获取声音()、获取名称()
【发布时间】:2018-12-27 07:28:45
【问题描述】:

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

  • getSound();获取名称();获取标识(); getGroup();

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

 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

【问题讨论】:

    标签: android notifications android-8.0-oreo notification-channel


    【解决方案1】:

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

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

    open app notification setting

    这可能对某人有所帮助。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 2021-10-20
      • 2017-12-30
      • 2014-01-19
      • 1970-01-01
      相关资源
      最近更新 更多