Gur*_*ran 5 notifications android push-notification firebase
我在我的应用程序中使用了FCM通知,我正在接收它们,它正在显示标题和消息
但是,当我收到通知时,我没有任何声音或振动或任何Led灯指示
我的通知生成器代码是
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());
Run Code Online (Sandbox Code Playgroud)
提前致谢.
firebase确保启用声音选项<uses-permission android:name="android.permission.VIBRATE" />
Run Code Online (Sandbox Code Playgroud)
通知的通知有效载荷有一个声音键.
从官方文档中可以看出:
表示设备收到通知时播放的声音.支持默认或应用程序中捆绑的声音资源的文件名.声音文件必须位于/ res/raw /中.
{
"to" : ".......",
"notification" : {
"body" : "body",
"title" : "title",
"icon" : "myicon",
"sound" : "default"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1973 次 |
| 最近记录: |