【发布时间】:2018-08-14 11:14:56
【问题描述】:
我已经为这个问题苦苦挣扎了很长时间,所以我决定问你。
我正在开发一个聊天应用程序,对于推送通知,我正在使用 Firebase 函数。我总是从 onMessageReceived 获取数据两次。对于某些人来说,解决方案是删除 de gcm 依赖项并仅使用 firebase 依赖项,但我认为不是我的情况。无论如何,我将向您展示所有代码:
这是我的 index.js:
exports.notifications = functions.database.ref('chats/{chatUid}/messages/{pushId}').onWrite( (change, context) => {
var valueObject = change.after.val();
var chatUid = change.after.ref.parent.parent.key;
var data = {
'data' : {
'conversation_id' : chatUid,
'message_key' : change.after.key,
'message_title' : valueObject.title,
'message_body' : valueObject.message,
'userFrom' : valueObject.userFrom.toString()
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToTopic(chatUid, data, options)
});
我的毕业设置:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
applicationId "xxx"
minSdkVersion 21
targetSdkVersion 27
versionCode xxx
versionName "x.x.x"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
productFlavors {
}
}
ext {
support_version = '27.1.1'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:customtabs:$support_version"
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation "com.android.support:percent:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation('com.squareup.retrofit2:retrofit:2.3.0') {
exclude module: 'okhttp'
}
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.facebook.android:facebook-android-sdk:4.18.0'
implementation 'com.google.firebase:firebase-analytics:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
implementation 'com.firebaseui:firebase-ui-storage:3.3.1'
implementation 'commons-codec:commons-codec:1.11'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'}
感谢您的宝贵时间:D
【问题讨论】:
标签: firebase push-notification firebase-cloud-messaging firebase-notifications