Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android背景下从firebase发送通知时,无通知声音、振动和灯光_Android_Firebase_Firebase Cloud Messaging - Fatal编程技术网

在android背景下从firebase发送通知时,无通知声音、振动和灯光

在android背景下从firebase发送通知时,无通知声音、振动和灯光,android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,我正在从firebase向我的Android应用程序发送推送通知。但当我的应用程序在后台时,不会调用firebase onMessageReceived方法,而是会将通知发送到系统,以便在系统托盘中显示通知。通知显示在系统托盘中,但没有通知声音,即使我在系统设置中允许应用程序发出通知声音。 这是我的通知代码 多谢各位 private void sendNotification(String msg, String title) { NotificationManager mNot

我正在从firebase向我的Android应用程序发送推送通知。但当我的应用程序在后台时,不会调用firebase onMessageReceived方法,而是会将通知发送到系统,以便在系统托盘中显示通知。通知显示在系统托盘中,但没有通知声音,即使我在系统设置中允许应用程序发出通知声音。 这是我的通知代码 多谢各位

    private void sendNotification(String msg, String title) {
    NotificationManager mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), 0);
    Intent i = new Intent(this,MainActivity.class);
    i.putExtra("","");

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(title)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                    .setContentText(msg);
    //Vibration
    mBuilder.setVibrate(new long[] { 200, 400, 600, 800, 1000 });

    //LED
    mBuilder.setLights(Color.MAGENTA, 1000, 1000);

    //Ton
    mBuilder.setSound(Uri.parse("android.resource://"
            + getApplicationContext().getPackageName() + "/" + R.raw.circles_notif));
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(0, mBuilder.build());
}

从firebase控制台转到通知>新消息>高级选项,并将通知作为自定义数据发送。使用“title”和“body”作为键,并按照您希望在通知中显示的方式放置它们的值。当应用程序处于后台或被终止时,应该调用onMessageReceived()

如果您是从自己的服务器发送通知,下面是一个示例json部分:

{   
    "data": {
      "title": "notification_title",
      "body": "notification_body"
    },
    "to" : "jh578_gsh....jhHGFJ76FH"
}

从firebase控制台转到通知>新消息>高级选项,并将通知作为自定义数据发送。使用“title”和“body”作为键,并按照您希望在通知中显示的方式放置它们的值。当应用程序处于后台或被终止时,应该调用onMessageReceived()

如果您是从自己的服务器发送通知,下面是一个示例json部分:

{   
    "data": {
      "title": "notification_title",
      "body": "notification_body"
    },
    "to" : "jh578_gsh....jhHGFJ76FH"
}
它写在,第二行评论说:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    ...
    Not getting messages here? See why this may be: ...goo.gl/39bRNJ
    ...
}

该解决方案与相关问题的答案一样,可在第节的文档中找到,其中说明:

接收包含通知和数据有效载荷的消息时,应用程序的行为取决于应用程序是在后台还是前台,在接收时是否处于活动状态

  • 在后台时,应用程序在通知托盘中接收通知负载,并且仅在用户点击通知时处理数据负载
  • 在前台时,您的应用程序会收到一个消息对象,其中两个有效负载都可用
它写在,第二行评论说:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    ...
    Not getting messages here? See why this may be: ...goo.gl/39bRNJ
    ...
}

该解决方案与相关问题的答案一样,可在第节的文档中找到,其中说明:

接收包含通知和数据有效载荷的消息时,应用程序的行为取决于应用程序是在后台还是前台,在接收时是否处于活动状态

  • 在后台时,应用程序在通知托盘中接收通知负载,并且仅在用户点击通知时处理数据负载
  • 在前台时,您的应用程序会收到一个消息对象,其中两个有效负载都可用
这似乎对我有用

虽然此不会在后台唤醒你的应用程序,但接受的答案会。

这似乎对我有效


虽然此不会在后台唤醒你的应用程序,但接受的答案会。

你在AndroidManifest中定义了android使用振动的权限吗?:
是,当我单击buton测试其工作时,这不是我的问题,但在后台不工作。你是否尝试过使用
设置默认值(全部默认值)
从NotificationCompat检查它是否与用户的默认首选项一起工作?并消除您仅为测试定义的振动、光线和声音。希望这对我有帮助,我尝试过,但同样的问题我有一个应用程序,通知与振动工作。与您的代码唯一的区别是,我的代码如下:
newnotificationcompat.Builder(this).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).setVimble(new long[]{400500300})未在
mBuilder
中定义。您是否定义了android在AndroidManifest中使用振动的权限?:
是,当我单击buton测试其工作时,这不是我的问题,但在后台不工作您是否尝试使用
设置默认值(全部默认值)
从NotificationCompat检查它是否与用户的默认首选项一起工作?并消除您仅为测试定义的振动、光线和声音。希望这对我有帮助,我尝试过,但同样的问题我有一个应用程序,通知与振动工作。与您的代码唯一的区别是,我的代码如下:
newnotificationcompat.Builder(this).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).setVimble(new long[]{400500300})未在
mBuilder
中定义。hello@sudip Podder当我想要的应用程序未收到通知时,我对此没有太多实际经验,但您可以点击以下链接:。看起来它可能提供了您正在寻找的解决方案。hello@sudip Podder当forground中的应用程序未收到通知时,我对此没有太多实际经验,但您可以点击以下链接:。看起来它可以提供您正在寻找的解决方案。