标签: firebase-cloud-messaging

找不到com.google.gms:google-services:4.0.1

嗨我开始在Android和导入firebase的新项目,如谷歌文档中所述.在Android studio 3.0.1中,一切都很完美.现在我将我的Android工作室更新为3.2.1.现在相同的代码重建并得到错误

找不到com.google.gms:google-services:4.0.1

记录是:

Could not find com.google.gms:google-services:4.0.1.
Searched in the following locations:
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/google/gms/google-services/4.0.1/google-services-4.0.1.jar
    https://jcenter.bintray.com/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom
    https://jcenter.bintray.com/com/google/gms/google-services/4.0.1/google-services-4.0.1.jar
    https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom
    https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.0.1/google-services-4.0.1.jar
Required by:
    project :
Run Code Online (Sandbox Code Playgroud)

我的项目级别Gradle是:

buildscript {

    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

应用级Gradle是:

apply plugin: 'com.android.application'

android …
Run Code Online (Sandbox Code Playgroud)

android google-play-services firebase-cloud-messaging

64
推荐指数
1
解决办法
8066
查看次数

FCM获得MismatchSenderId

我有一个使用Google FCM发送推送通知的应用程序.

当我向一组用户发送推送通知时,我得到了MismatchSenderId一些用户的回复.尽管如此,所有用户都拥有完全相同的应用程序.一些用户如何获得成功响应而其他用户获得MismatchSenderId?

我已经研究了很多,并确保我已经添加了FCM所需的所有先决条件.

有什么建议?

编辑:

样品回复:

{"multicast_id":5340432438815499122,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
Run Code Online (Sandbox Code Playgroud)

编辑2:

这是服务器端发送代码(PHP):

$fields = array
(
  'to' => $token,
  'data' => $data
);

$headers = array
(
  'Authorization: key=AIza**************************',
  'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode($fields) );
curl_exec( $ch );
curl_close( $ch );
Run Code Online (Sandbox Code Playgroud)

更新:

似乎已通过SDK更新解决了该问题.我现在正在使用最新版本com.google.firebase:firebase-messaging:9.6.1,我不再使用"MismatchSenderId"了.

firebase firebase-cloud-messaging

63
推荐指数
10
解决办法
8万
查看次数

从android中的firebase发送通知时没有通知声音

我正在从firebase向我的Android应用程序发送推送通知.但是当我的应用程序处于后台时,不会调用firebase onMessageReceived方法而是调用firebase向系统发送通知,以便在系统托盘中显示通知.通知出现在系统托盘中但没有通知声音,即使我已在系统设置中允许我的应用程序发出通知声音.

当从firebase收到通知时,我可以做什么来播放通知声音.

这就是我从firebase向我的应用Blogpost链接发送通知的方式.

如何在Android应用程序中添加firebase

notifications android push-notification firebase firebase-cloud-messaging

63
推荐指数
7
解决办法
8万
查看次数

如何通过CURL向所有设备发送Firebase通知?

我正在尝试向所有应用用户(在Android上)发送通知,基本上会复制通过Firebase管理控制台发送通知时发生的情况.这是我开始的CURL命令:

curl --insecure --header"授权:key = AIzaSyBidmyauthkeyisfineL-6NcJxj-1JUvEM"--header"Content-Type:application/json"-d"{\"notification \":{\"title \":\"note -Title \",\"body \":\"note-Body \"}}" https://fcm.googleapis.com/fcm/send

这是JSON解析出来更方便你的眼睛:

{
"notification":{
    "title":"note-Title",
    "body":"note-Body"
    }
}
Run Code Online (Sandbox Code Playgroud)

回复的响应只有两个字符:

就是这样,"to"这个词.(Headers报告400)我怀疑这与我的JSON中没有"to"有关.人们甚至会为"去"做什么?我没有定义主题,设备没有注册任何东西.但是,他们仍然可以从Firebase管理面板接收通知.

由于Firebase通知处理的惊人限制,我想尝试"仅数据"JSON包,如果您的应用程序在前台,通知将由您的处理程序处理,但如果您的应用程序在后台,则会获得由Firebase服务内部处理,并且从未传递给您的通知处理程序.显然,如果您通过API提交通知请求,则可以解决此问题,但仅限于仅使用数据进行通知请求.(这会破坏使用相同消息处理iOS和Android的能力.)在我的任何JSON中用"data"替换"notification"都没有效果.

好的,然后我在这里尝试了解决方案:Firebase Java Server向所有设备发送推送通知, 在我看来说"好吧,即使通过管理控制台向所有人发送通知......也不可能通过API. " 解决方法是让每个客户端订阅一个主题,然后将通知推送到该主题.首先是onCreate中的代码:

FirebaseMessaging.getInstance().subscribeToTopic("allDevices");
Run Code Online (Sandbox Code Playgroud)

那么我发送的新JSON:

{
"notification":{
    "title":"note-Title",
    "body":"note-Body"
    },
"to":"allDevices"
}
Run Code Online (Sandbox Code Playgroud)

所以现在我至少得到了服务器的真实回复.JSON响应:

{
"multicast_id":463numbersnumbers42000,
"success":0,
"failure":1,
"canonical_ids":0,
"results":
    [
    {
    "error":"InvalidRegistration"
    }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这附带一个HTTP代码200.好的......根据https://firebase.google.com/docs/cloud-messaging/http-server-ref,带有"InvalidRegistration"的200代码表示注册令牌存在问题.也许?因为文档的这一部分是针对消息传递服务器的.通知服务器是否相同?不清楚.我在其他地方看到这个主题可能需要几个小时才能激活.这似乎会使创建新的聊天室变得毫无用处,所以这似乎也是如此.

当我从头开始编写应用程序时,我很兴奋,因为我以前从未使用过Firebase,只需几个小时即可收到通知.在达到Stripe.com文档的水平之前,它似乎还有很长的路要走.

一句话:有没有人知道提供什么JSON来向运行应用程序的所有设备发送消息以镜像管理控制台功能?

android firebase firebase-cloud-messaging firebase-notifications

61
推荐指数
3
解决办法
8万
查看次数

60
推荐指数
3
解决办法
4万
查看次数

Firebase云消息传递 - 处理注销

当用户退出我的应用程序并且我不再希望他接收到设备的通知时,我该如何处理这种情况.

我试过了

FirebaseInstanceId.getInstance().deleteToken(FirebaseInstanceId.getInstance().getId(), FirebaseMessaging.INSTANCE_ID_SCOPE)
Run Code Online (Sandbox Code Playgroud)

但我仍然收到我的设备的通知registration_id.

我还确保这是我应删除的令牌:

FirebaseInstanceId.getInstance().getToken(FirebaseInstanceId.getInstance().getId(), FirebaseMessaging.INSTANCE_ID_SCOPE)
Run Code Online (Sandbox Code Playgroud)

或者简单地说FirebaseInstanceId.getInstance().getToken()).

我也尝试过FirebaseInstanceId.getInstance().deleteInstanceId(),但是下次我打电话给FirebaseInstanceId.getInstance.getToken我时会收到空(它在第二次尝试时起作用).

我想,在deleteInstanceId我能够立即getToken()再次打电话之后,它看起来像是一个黑客.并且还有这个答案表明不应该这样做,但它建议删除显然不起作用的令牌.

那么处理这个问题的正确方法是什么?

android firebase firebase-cloud-messaging

59
推荐指数
6
解决办法
3万
查看次数

设备未收到Firebase云消息传递通知

我有火力点云信息的问题,我从设备获取的令牌,并不过,在透过谷歌火力地堡通知控制台发送通知测试,该通知从未登录,也被推到了Android的虚拟设备.对于FCM的文档几乎一模一样,我有以下及一些其它在还有什么你必须做的就是推送通知与火力的工作方式的代码.我已经完成了所有的设置信息了(的build.gradle增加,安装谷歌播放服务等)的文件中规定,但仍然没有消息产生.我按下通知后立即收到一次性错误,指出"I/FA:找不到标签管理器,因此不会被使用",但这是唯一输出的数据,我没有找到与标签相关的任何内容经理要求和谷歌上的FCM.我没有收到对logcat或设备的推送通知的代码有什么问题?请让我知道任何有用的进一步信息.谢谢.

NotificationGenie.java

public class NotificationGenie extends FirebaseMessagingService {

private static final String TAG = "Firebase_MSG";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
    sendNotification(remoteMessage.getNotification().getBody());
    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification …
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-messaging firebase-cloud-messaging

55
推荐指数
11
解决办法
11万
查看次数

Firebase云消息是免费的吗?

我需要在我的应用程序中实现推送通知功能.探索一些选择.

谷歌最近推荐使用Firebase平台,但这不是一个完全免费的服务.所以我想再次使用GCM.google将来是否会停止对GCM的支持?

android push-notification firebase google-cloud-messaging firebase-cloud-messaging

54
推荐指数
5
解决办法
7万
查看次数

com.google.android.gms.common.internal.safe parcel.safe parcelable not found

我正在尝试使用FCM和https://www.simplifiedcoding.net/firebase-cloud-messaging-android/上的教程向我的应用添加通知服务. 一切都已完成并且像获取令牌等工作但现在在创建消息处理程序之后,我开始收到错误:

Error:(22, 26) error: cannot access AbstractSafeParcelable
class file for com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable not found
Run Code Online (Sandbox Code Playgroud)

并且构建失败.请指导.gradle的代码是:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }

    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven {
        url "https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/"
    }
}


android {
    compileSdkVersion 25
    buildToolsVersion "24.0.3"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "jss.smartapp"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release …
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-cloud-messaging

52
推荐指数
3
解决办法
5万
查看次数

Firebase:无法上传生产APNs证书

我目前正在测试TestFlight中的应用程序并需要生产APNs证书才能测试Firebase中的通知.

我已按照此视频中的所有步骤成功配置了开发APNs证书:https://www.youtube.com/watch?v = LBw5tuTvKd4

我还检查了Firebase支持指南后的步骤.虽然我注意到Apple开发者网站自编写本指南以来略有变化:https: //firebase.google.com/docs/cloud-messaging/ios/certs#configure_an_app_id_for_push_notifications

我使用与开发证书相同的方法在developer.apple.com上生成了生产APNs证书,但是当我尝试将.p12文件上传到Firebase时,它给出了以下错误:

"证书环境不匹配.确保您获得了正确的开发或生产APNS证书."

我肯定会上传从生产APNS证书生成的.p12,我还需要为生产证书做些什么吗?

push-notification apple-push-notifications ios firebase firebase-cloud-messaging

49
推荐指数
2
解决办法
3万
查看次数