#Hey guys, how do i get importance, hasSound and hasVibration on Android API 26 and above?

1 messages · Page 1 of 1 (latest)

marble crestBOT
#

<@&987246964494204979> please have a look, thanks.

frail bay
#
@Override
    public void onNotificationPosted(StatusBarNotification sbn) 
    {
        Bundle extras = sbn.getNotification().extras;

        String pkg = sbn.getPackageName();
        String title = extras.getString("android.title", "");
        String text = extras.getString("android.text", "");

        int importance = 0;
        boolean hasSound = false;
        boolean hasVibrate = false;

        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) 
        {
            String channelId = sbn.getNotification().getChannelId();
            UnityPlayer.UnitySendMessage(UNITY_OBJECT, "Log", "Channel ID: " + channelId);
            if (channelId != null) 
            {
                NotificationChannel channel = nm.getNotificationChannel(channelId);
                UnityPlayer.UnitySendMessage(UNITY_OBJECT, "Log", "Channel: " + channel);
                if (channel != null) 
                {
                    importance = channel.getImportance() + 1;
                    hasSound = channel.getSound() != null;
                    hasVibrate = channel.shouldVibrate();
                }
            }
        }

        String payload = pkg + "||" + title + "||" + text + "||" + importance + "||" + (hasSound ? "1" : "0") + "||" + (hasVibrate ? "1" : "0");
marble crestBOT
# frail bay ```java @Override public void onNotificationPosted(StatusBarNotification sbn...

Detected code, here are some useful tools:

Formatted code
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
  Bundle extras = sbn.getNotification().extras;
  String pkg = sbn.getPackageName();
  String title = extras.getString("android.title", "");
  String text = extras.getString("android.text", "");
  int importance = 0;
  boolean hasSound = false;
  boolean hasVibrate = false;
  NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    String channelId = sbn.getNotification().getChannelId();
    UnityPlayer.UnitySendMessage(UNITY_OBJECT, "Log", "Channel ID: " + channelId);
    if (channelId != null ) {
      NotificationChannel channel = nm.getNotificationChannel(channelId);
      UnityPlayer.UnitySendMessage(UNITY_OBJECT, "Log", "Channel: " + channel);
      if (channel != null ) {
        importance = channel.getImportance() + 1;
        hasSound = channel.getSound() != null ;
        hasVibrate = channel.shouldVibrate();
      }
    }
  }
  String payload = pkg + "||" + title + "||" + text + "||" + importance + "||" + (hasSound ? "1" : "0") + "||" + (hasVibrate ? "1" : "0");
marble crestBOT
frail bay
#

oops ignore this bot i just wanted it to go away and called it twice, sorry

#

does android not allow me to access other app's notification's channels?