2017-05-08 175 views
0

我目前正在开发一个应用程序,它的通知系统运行良好。除了当我从firebase发送消息到手机时,通知不会发出声音(默认电话声音)。问题是我的java程序出了什么问题。通知声音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()); 


} 

回答

0

Repalce按照你的代码行:

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

这样你就可以访问您的自定义通知声音。