Firebase云消息没有任何声音

时间:2018-11-18 09:57:49

标签: android firebase android-studio firebase-cloud-messaging

我正在使用云消息传递应用程序,并且正在通过此代码使用Firebase云消息

public class NotificationHelper {

    public static void displayNotification(Context context, String title, String body) {
        Uri alertSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder  mBuilder =
                new NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
                        .setSmallIcon(R.drawable.ic_gift )
                        .setContentTitle(title)
                        .setContentText(body)
                        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                        .setSound(alertSound);

        NotificationManagerCompat notificationManagerCompat =  NotificationManagerCompat.from(context);
        notificationManagerCompat.notify(1, mBuilder.build());
    }
}

这就是服务。

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        if (remoteMessage.getNotification() != null) {
            String title = remoteMessage.getNotification().getTitle();
            String text = remoteMessage.getNotification().getBody();
            NotificationHelper.displayNotification(getApplicationContext(), title, text);
        }
    }
}

这是清单XML代码

<service
    android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
    </intent-filter>
</service>

消息来了,但是没有声音,我不知道代码中有什么错误,请任何人都可以帮助我

0 个答案:

没有答案