2017-05-08 2 views
0

Je développe actuellement une application et son système de notification fonctionne bien. Sauf quand j'envoie un message de Firebase au téléphone, la notification ne fait pas de bruit (son de téléphone par défaut). La question est de savoir ce qui ne va pas dans mon programme Java.Notification sonore android studio

private void sendNotification(String messageBody) { 
    Intent intent = new Intent(this, page1.class);//**The activity that you want to open when the notification is clicked 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
      PendingIntent.FLAG_ONE_SHOT); 


    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); 

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle("FCM Message") 
      .setContentText(messageBody) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 
    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); 


} 

Répondre

0

repalce ligne suivante dans votre code:

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
0
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.cutomSound); 

De cette façon, vous pouvez accéder à votre son de notification personnalisée.