【问题标题】:Notification sound android studio [duplicate]通知声音android studio [重复]
【发布时间】:2017-05-08 07:45:45
【问题描述】:

我目前正在开发一个应用程序,它的通知系统运行良好。除非我从 firebase 向手机发送消息,否则通知不会发出声音(默认手机声音)。问题是我的 java 程序出了什么问题。

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());


}

【问题讨论】:

    标签: java android firebase push-notification ringtonemanager


    【解决方案1】:

    替换代码中的以下行:

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

    【讨论】:

      【解决方案2】:
      Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.cutomSound);
      

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

      【讨论】:

        猜你喜欢
        • 2012-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多