小编Ser*_*Kim的帖子

MIUI无声推送通知

我的应用程序的主要功能是从远程服务器发送的推送通知消息。我使用 FCM 作为消息传递服务。我的问题是小米米 9 Lite (Android 9/MIUI 11) 上的通知没有任何声音。但是,在小米红米 Note 5 (Android 9/MIUI 10) 上声音工作正常,在三星 Galaxy S7 Edge (Android 8) 上也能正常工作。我创建了 MessagingService,它扩展了 FirebaseMessagingService 和文档中编写的通知通道。

这是我的代码:

public class MessagingService extends FirebaseMessagingService {

    private static String channelId;
    private NotificationManager notificationManager;
    private NotificationChannel notificationChannel;
    private NotificationCompat.Builder notificationBuilder;

    private MessagesViewModel viewModel;

    public MessagingService() { }

    @Override
    public void onCreate() {
        super.onCreate();
        channelId = getResources().getString(R.string.default_notification_channel_id);
        notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

        final Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationBuilder = new NotificationCompat.Builder(this, channelId);
        notificationBuilder.setSmallIcon(R.raw.metrial_message_icon);
        notificationBuilder.setAutoCancel(false);
        notificationBuilder.setSound(soundUri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) …
Run Code Online (Sandbox Code Playgroud)

java android push-notification miui

9
推荐指数
1
解决办法
3181
查看次数

标签 统计

android ×1

java ×1

miui ×1

push-notification ×1