Android 通知没有声音和振动 [英] Android Notification Not getting Sound And Vibration

查看:140
本文介绍了Android 通知没有声音和振动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用了 FCM 通知,我正在接收它们,它完美地显示了标题和消息

I've used FCM Notifications in My app , I'm Receiving Them and it's showing Title And message Perfectly

但是,当我收到通知时,我没有听到任何声音、振动或任何 LED 灯指示

But,When i'm receiving the Notification Im not getting any sound or vibration or any Led light indication

我的通知生成器代码是

My Notification Builder Code is

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder.setSmallIcon(R.drawable.applogo);
    builder.setContentTitle(Title);
    builder.setContentText(Message);
    builder.setAutoCancel(true);
    builder.setSound(Uri.parse("file:///android_asset/notification.mp3"));
    builder.setContentIntent(pendingIntent);
    builder.setDefaults(Notification.DEFAULT_VIBRATE);
    builder.setLights(Color.RED, 1000, 300);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, builder.build());

提前致谢.

推荐答案

1. 当您从 firebase 发送推送通知时,请确保启用声音选项

喜欢这个

1. When you send push notification from firebase make sure that sound option enabled

like this

<uses-permission android:name="android.permission.VIBRATE" />

3.如果您是从服务器发送而不是使用有效载荷

notification payload 有一个声音键的通知.

3. If you are sending from server than use payload

notification payload of the notification there is a sound key.

从官方文档来看,它的用法是:

From the official documentation its use is:

表示设备收到通知时播放的声音.支持应用程序中捆绑的声音资源的默认或文件名.声音文件必须驻留在/res/raw/中.

Indicates a sound to play when the device receives a notification. Supports default or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/.

{
    "to" : ".......",

    "notification" : {
      "body" : "body",
      "title" : "title",
      "icon" : "myicon",
      "sound" : "default"
    }
  }

这篇关于Android 通知没有声音和振动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆