Android Wear Notification is not displayed if FLAG_NO_CLEAR is used

后端 未结 2 1393
攒了一身酷
攒了一身酷 2020-12-17 18:18

If flag \"FLAG_NO_CLEAR\" is used the notification gets not displayed on the Android Wear.

Does anyone know why or any workaround?

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 19:03

    Honestly something really weird changed in wear 1.5 so a solution would be to set an alarm

    Uri alarmSound = getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    
    
        Intent displayIntent = new Intent(this, WearNotif.class);
        //displayIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent displayPendingIntent = PendingIntent.getActivity(this,
                0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("WeirdShit")
                .setContentText("some random crap")
                .extend(new Notification.WearableExtender()
                        .setDisplayIntent(displayPendingIntent))
                .setSound(alarmSound)
                .build();
    
        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(this);
        notificationManager.notify(25454, notification);
    

提交回复
热议问题