小编use*_*921的帖子

当我们在另一个应用程序中时,Android 10 来电通知就像什么应用程序一样

一旦我们在 android 10 后台启动活动受限时收到 FCM 推送通知消息。当我们在另一个应用程序中时,需要像 WhatsApp 和 Skype 通知来电这样的解决方案。

在此处输入图片说明

int NOTIFICATIONID = 1234;
       // Uri sound =  RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.capv_callingtone);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build();
            String CHANNEL_ID = BuildConfig.APPLICATION_ID.concat("_notification_id");
            String CHANNEL_NAME = BuildConfig.APPLICATION_ID.concat("_notification_name");
            assert notificationManager != null;

            NotificationChannel mChannel = notificationManager.getNotificationChannel(CHANNEL_ID);
            if (mChannel == null) {
                mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
                mChannel.setSound(sound, audioAttributes);
                notificationManager.createNotificationChannel(mChannel);
            }
            in.setClass(CapVFirebaseMessagingService.this, DashBoardActivity.class); …
Run Code Online (Sandbox Code Playgroud)

android android-notifications whatsapp firebase-cloud-messaging

11
推荐指数
1
解决办法
1万
查看次数