徽章计数器索尼,三星Android奥利奥和。馅饼

问题描述 投票:0回答:1

我正在研究一个Android应用程序,我需要在应用程序的主要图标中显示一个帐户,在android oreo中工作类通知徽章,但在谷歌像素中的android 9中没有显示它,并且在Sony Xperia XZ2中与android Pie不起作用,它不显示未读通知图标。

我尝试过像ShortcutBadger之类的第三方库,但它们与新的Android版本不兼容

NotificationChannel fyfChannel = new NotificationChannel(FYF_CHANNEL__ID, FYF_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
    fyfChannel.enableLights(true);
    fyfChannel.enableVibration(true);
    fyfChannel.setLightColor(Color.GREEN);
 fyfChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    fyfChannel.setShowBadge(true);
    AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
    fyfChannel.setSound( Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.audio1), audioAttributes);
    getManager().createNotificationChannel(fyfChannel);
java android notifications sony badge
1个回答
0
投票

请试试这个:

String NOTIF_CHANNEL_ID = "my_notification_channel";

Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this, NOTIF_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_notification)
                .setContentText(message)
                .setContentTitle("RideWhiz")
                .setAutoCancel(true)
                .setSound(sound)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            // Configure the notification channel.
            NotificationChannel notifChannel = new NotificationChannel(NOTIF_CHANNEL_ID, message, NotificationManager.IMPORTANCE_DEFAULT);
            notifChannel.setDescription(message);
            notifChannel.enableLights(true);
            notifChannel.setLightColor(Color.GREEN);
            notifChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
            notifChannel.enableVibration(true);
            notificationManager.createNotificationChannel(notifChannel);
        }

        notificationManager.notify((int)System.currentTimeMillis(), notifBuilder.build());
© www.soinside.com 2019 - 2024. All rights reserved.