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

查看:1441
本文介绍了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

我的Notification Builder代码是

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..如果您是从服务器发送而不是使用有效负载

通知的通知有效负载中有一个声音键.

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天全站免登陆