- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在我的 Android 应用程序中实现了 firebase 云消息传递。当我从支持的控制台或 Firebase 控制台发送通知时 onMessageReceived()
被触发两次并在设备上生成两个通知。我试图在互联网上搜索,但没有找到与此问题相关的结果
这是我的代码,
MyFirebaseNotificationService.java
public class MyFirebaseNotificationService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
MyApp.getInstance().saveFCMToken(s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
int notificationId = new Random().nextInt(60000);
String customerId = "";
Log.e("NOTIF", "" + remoteMessage.getData());
Intent notificationIntent = new Intent(this, SplashActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationIntent.setAction(Long.toString(System.currentTimeMillis()));
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "100")
.setSmallIcon(R.drawable.ic_app_icon)
.setColorized(true)
.setPriority(PRIORITY_HIGH)
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setContentTitle(Html.fromHtml(remoteMessage.getData().get("title")))
.setContentText(Html.fromHtml(remoteMessage.getData().get("message")))
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
createNotificationChannel();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, notificationBuilder.build());
}
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Exchange Customer";
String description = "Sales Buddy";
String CHANNEL_ID = "100";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
}
}
AndroidManifest
<service android:name=".sevices.MyFirebaseNotificationService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
list 中的权限
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
在收到消息时,我已经记录了通知,这里是 logcat
2019-05-01 15:08:54.415 29417-29501/in.example.one E/NOTIF: {extras={"customerId":"5e341186-6bd4-11e9-9069-44a8422a303b"}, type=exchange, title=Test User:1556703533, message=Test User1}
2019-05-01 15:08:58.542 29417-29501/in.example.one E/NOTIF: {extras={"customerId":"5e341186-6bd4-11e9-9069-44a8422a303b"}, type=exchange, title=Test User:1556703533, message=Test User1}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.26.1'
}
模块 Gradle 文件
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.amitshekhar.android:android-networking:1.0.2'
implementation 'com.github.WindSekirun:SectionCalendarView:1.0.5.1'
implementation 'com.github.darsh2:MultipleImageSelect:v0.0.4'
implementation 'com.bogdwellers:pinchtozoom:0.1'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation 'com.google.firebase:firebase-database:16.1.0'
}
我的 PHP 代码
$extras= json_encode(['customerId' => "5e341186-6bd4-11e9-9069-44a8422a303b"]);
$data=array(
'title'=> "Test User:".time(),
'message'=> "Test User1",
'type'=> "exchange",
'extras'=>$extras
);
$notification=array(
'title'=> "Test User:".time(),
'body'=> "body1",
);
$fields = array
(
'to'=>'/topics/test-exchange-persons-sales-buddy',
'data' => $data
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'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, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
最佳答案
我有同样的问题,但使用 Firebase 消息传递主题。我收到两个通知,因为“onMessageReceived”像你一样调用了两次。也许今天 FCM 有问题?
关于Android FirebaseMessaging Service onMessageReceived 调用了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55934466/
收到此错误我已尝试修复此引用:Application.kt: Unresolved reference: firebasemessaging但没有工作,所以我需要再次发布我也尝试删除 applicat
我有一个 flutter 应用程序,在某些时候管理员用户可以保存一份出版物。 现在我希望所有用户在该出版物发布时收到通知(包括标题、描述等)。 我如何使用 Firebase 消息传递来做到这一点? 我
我有以下基本示例,它似乎无法正常工作: pubspec.yaml: firebase_messaging: ^10.0.0 FcmService.dart StreamSubscription fcm
您好,我想知道是否有一种方法可以使用 Firestore 消息传递和 flutter 来合并通知,就像 instagram 所做的那样。最初它会说一个人喜欢一个帖子 e.t.c 然后如果更喜欢这个帖子
我有 6 个错误,我什至无法想象它可能是什么。 也许有人见过她。 错误截图 最佳答案 从终端重新安装 Pod 可以解决您的问题。- 打开终端并转到项目目录并运行 pod install 命令。 关于i
我添加了依赖 编译 'com.google.android.gms:play-services-tagmanager:9.0.0' 编译 'com.google.firebase:firebase-m
我正在尝试 Firebase 云消息 ,我按照这个例子中的说明here但我在我的 android studio 的 log cat 窗口中发现了这条消息: com.example.tareq.news
我添加了一个 FirebaseMessagingService 类来接收前台通知。我没有收到前台通知。在后台,当应用程序最小化时,它工作正常。 我已经使用 firebase 函数设置了后台通知,并且工
我已经在我的 Android 应用程序中实现了 firebase 云消息传递。当我从支持的控制台或 Firebase 控制台发送通知时 onMessageReceived()被触发两次并在设备上生成两
我在用: flutter version 2.2 firebase_messaging: ^10.0.2 我收到推送通知,然后单击它并打开应用程序。 然后我看不到FirebaseMessaging.o
我正在尝试更新 firebase_messaging到新版本8.0.0-dev.10 . 但是,我收到以下错误: Running Gradle task 'assembleDebug'... Appl
我的应用尝试使用 Firebase 远程通知,我遵循了 Firebase 指南。现在,我的应用程序在 AppDelegate 中崩溃,我在其中尝试设置 Firebase 消息传递的委托(delegat
我一直在使用pod 'FirebaseMessaging'成功了一段时间: pod 'FirebaseMessaging', '2.2.0' 尝试更新到新版本 pod 'FirebaseMessagi
我知道创建一个名为 FirebaseApp 的能力带有自定义选项的实例,例如 FirebaseDatabase , 但我特别需要使用 FirebaseMessagaging 的能力针对不同的(在运行时
我收到“找不到 FirebaseMessaging 模块”的错误。下面是我的 pod 文件结构。 官方文档显示 Firebase/Messaging 可用。我已经写在 pod 文件中并尝试安装它。终端
我是 flutter 的新手。我刚刚将一个为我构建的项目升级到 flutter 2.0,我不确定如何解决这个特定问题。我用谷歌搜索并找到了例子。我知道这里有改进,可能会解决我的应用程序面临的问题之一。
当我写@import FirebaseMessaging; 时,它说 - 未找到模块“FirebaseMessaging” 我做了什么 - 起初我只安装了 Firebase/Core 的 pod,但后
我正在尝试使用 FirebaseMessaging ^8.0.0-dev.14 向我的应用程序的用户发送推送通知,但我遇到了一些问题。我能够在 IOS 上收到通知,但在我的 Android 模拟器上没
应用程序在添加适用于 iOS 的 FirebaseMessaging 时加载时崩溃。React-native 版本:0.60.4 从 https://github.com/WebEngage/reac
我正在尝试在 Flutter 应用程序中使用 Firebase 消息传递。我遵循包装中的所有说明。 在我的 pubspec.yaml 我有这些包: dependencies: flutter:
我是一名优秀的程序员,十分优秀!