[問題] 推播沒設定音效問題

看板AndroidDev作者 (充實過每一天)時間1月前 (2024/10/05 10:42), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
因為FCM改版,改版推播有設定音效,但上架google play下載的APP安裝部分手機還是沒依據我設定 我設的音樂檔,但沒音樂的程式compiler到手機 測試是有音樂的耶! 我抓不到問題有android13、14手機不行,但也有android14可以 Root rootObj = new Root(); rootObj.message = new Message(); rootObj.message.token = "xxxx"; // FCM Token id // Data payload rootObj.message.data = new Data(); rootObj.message.data.title = "test"; rootObj.message.data.body = "test me"; rootObj.message.data.key_1 = "Sample Key"; rootObj.message.data.key_2 = "Sample Key2"; // Android-specific notification payload rootObj.message.android = new Android(); rootObj.message.android.priority = "high"; // 設定優先級為 high rootObj.message.android.notification = new AndroidNotification(); rootObj.message.android.notification.title = "test"; rootObj.message.android.notification.body = "send data20241004"; rootObj.message.android.notification.sound = "pushmusic2"; // Sound file in Android app's raw folder rootObj.message.android.notification.channel_id = "xxx"; // Notification channel I ------------------- if (remoteMessage.getNotification() != null) { String title = remoteMessage.getNotification().getTitle(); String body = remoteMessage.getNotification().getBody(); sendNotification3(body); } Intent intent = new Intent(this, FirstActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "xxx") .setSmallIcon(R.drawable.pcar) // 替換為你的圖示 .setContentTitle("xxx") .setContentText(messageBody) .setAutoCancel(true) .setContentIntent(pendingIntent) .setSound(Uri.parse("android.resource://" + getPackageName() + "/raw/pushmusic2")) // 指定聲音文件 .setPriority(NotificationCompat.PRIORITY_HIGH); // 設定通知優 先級 NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Android 8.0+ 需要設定 Notification Channel if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_NOTIFICATION) .build(); NotificationChannel channel = new NotificationChannel("xxx", "xxNotifications", NotificationManager.IMPORTANCE_HIGH); channel.setSound(Uri.parse("android.resource://" + getPackageName() + "/raw/pushmusic2"), audioAttributes); notificationManager.createNotificationChannel(channel); } // 顯示通知 notificationManager.notify(0, notificationBuilder.build()); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.79.19.49 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1728096166.A.F08.html
文章代碼(AID): #1d0AUcy8 (AndroidDev)
文章代碼(AID): #1d0AUcy8 (AndroidDev)