#Hey guys, how do i get importance, hasSound and hasVibration on Android API 26 and above?
1 messages · Page 1 of 1 (latest)
@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");
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");
Detected code, here are some useful tools: