在我MainActivity
的日志中,我可以看到使用的令牌FirebaseInstanceId.getInstance().getToken()
,它显示生成的令牌.但似乎在我 MyFirebaseInstanceIDService
扩展到的地方FirebaseInstanceIdService
,onTokenRefresh()
没有被调用,在这个函数中,据说令牌最初是在这里生成的.我需要打电话给我,sendRegistrationToServer()
这就是为什么我想知道它为什么不进入的原因onTokenRefresh()
.
这是我的代码
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
}
Run Code Online (Sandbox Code Playgroud) android firebase firebase-cloud-messaging firebase-notifications
我正在尝试使用Firebase-Notification API,当我将下游消息从控制台发送到应用程序时,该服务是完美的,但如何向主题注册用户发送消息?
我在android方面做过
FirebaseMessaging.getInstance().subscribeToTopic("TopicName");
Run Code Online (Sandbox Code Playgroud)
但当我尝试从控制台向主题发送下游消息时,它说
This project does not have any topics
Run Code Online (Sandbox Code Playgroud)
编辑:我发现在映射主题后,最多需要1天才能显示在Firebase控制台中
android firebase google-cloud-messaging firebase-notifications
我在SO上读过类似的问题,然而,我无法从中得到正确的答案.
我有一个系统,我们向大约500个设备发送通知.
不幸的是,许多这些设备没有收到通知.我发现OPPO F1系列手机特别没有收到通知.
我发现,如果应用程序从多任务托盘中停止,则会发生这种情况.我该如何解决这个问题?
更新:我观察到当我从任务托盘关闭应用程序时,我的应用程序被强制停在应用程序管理器中.当我从任务托盘关闭Whatsapp时,仍然没有强制停止.怎么被Whatsapp处理?
android firebase firebase-cloud-messaging firebase-notifications
我正在尝试向所有应用用户(在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
在新的Firebase中,在通知下,他们提到开发人员可以向特定设备发送通知.为此,在控制台中它要求一个FCM令牌.究竟是什么,我如何获得该令牌?
android firebase firebase-cloud-messaging firebase-notifications
当用户在后台点击通知时,我正在尝试打开特定活动.从Docs中,我已经知道必须在有效负载中添加click_action,并在App中使用intent过滤来处理它.但是,如何通过Firebase控制台在Firebase通知中添加click_action?我也对任何其他工作开放.提前致谢.
android android-notifications firebase-cloud-messaging firebase-notifications
对于Swift3/iOS10,请看此链接:
ios10,Swift 3和Firebase推送通知(FCM)
我正在尝试使用Firebase进行通知,我完全按照文档中的描述进行了集成.但我不明白为什么不起作用.当我构建我的项目时,我看到这一行:
2016-05-25 16:09:34.987: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
Run Code Online (Sandbox Code Playgroud)
这是我的AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
var service: DataService = DataService()
service.start()
registerForPushNotifications(application)
application.registerForRemoteNotifications()
return true
}
func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { …
Run Code Online (Sandbox Code Playgroud) 我使用FCM控制台发送推送通知,它可以选择安排交付日期.
但是在参考文献中,此API未作为选项进行记录.我需要知道是否可以通过POST请求推送具有预定义交付日期的通知.
我希望在收到通知时自动打开应用程序,Firebase和新的FCM通知是否可以实现?
我知道我可以设置click_action,但这只是为了自定义通知点击会启动哪些活动,我需要在收到通知时自动启动的内容.
我尝试了快速启动消息传递firebase示例,并且有一个onMessageReceived()方法,但只有在应用程序位于前台时它才有效.应用程序在后台运行时是否会执行某些操作?GCM可以通过直接启动广播接收器的活动意图来做我喜欢的事情,广播接收器在收到通知时调用.
android firebase firebase-cloud-messaging firebase-notifications
我试图在Activity
点击通知时打开,下面是我的代码.
Intent intent = new Intent(this.getApplicationContext(), NotificationActivity.class);
intent.putExtra("msgBody",messageBody);
intent.putExtra(Constants.NOTIF_INTENT_TYPE,Constants.NOTIF_INTENT_TYPE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|Intent.FLAG_ACTIVITY_SINGLE_TOP
|Intent.FLAG_ACTIVITY_CLEAR_TOP); //Tried with many options here
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
PendingIntent.FLAG_CANCEL_CURRENT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.otp_icon)
.setContentTitle("Push MSG")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.com.pushapp">
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".AndroidPushApp" …
Run Code Online (Sandbox Code Playgroud) java android push-notification firebase-cloud-messaging firebase-notifications