您好,我有两种设备:其中一种是10英寸平板电脑 另一个是android pc。
manifest.xml
<service
android:name=".Helpers.FCMMessagingService"
android:enabled="true"
android:exported="true"
tools:ignore="InnerclassSeparator">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
FCMMessagingService
class FCMMessagingService : FirebaseMessagingService() {
companion object {
fun configureFCM() {
try {
FirebaseMessaging.getInstance().subscribeToTopic("intek")
.addOnCompleteListener { task ->
var msg = "success"
if (!task.isSuccessful) {
msg = "failed"
}
Log.i("test", msg)
}
.addOnFailureListener { e ->
Log.i("test", e.message)
}
} catch (e: Throwable) {
Log.i("avs", e.message)
}
}
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
val message = remoteMessage.notification?.body
if (message != null) {
showAlert(message)
}
super.onMessageReceived(remoteMessage)
}
fun showAlert(msg: String) {
if (Utils.currentContext != null) {
Alerter.create(Utils.currentContext!!)
.setTitle("Duyuru")
.setText(msg)
.show()
}
}
}
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.intek.posseal"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
implementation 'com.github.TutorialsAndroid:KAlertDialog:v7.0.19'
implementation 'com.ernestoyaquello.dragdropswiperecyclerview:drag-drop-swipe-recyclerview:0.5.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation "org.jetbrains.anko:anko-commons:0.10.4"
implementation 'com.github.Nikoloutsos:KLoadingSpin:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation "android.arch.lifecycle:extensions:1.1.1" // local db
//noinspection LifecycleAnnotationProcessorWithJava8
kapt "android.arch.lifecycle:compiler:1.1.1" // local db
implementation "android.arch.persistence.room:runtime:1.1.1" // local db
kapt "android.arch.persistence.room:compiler:1.1.1" // local db
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.gms:google-services:4.3.3'
implementation 'com.tapadoo.android:alerter:4.0.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.github.felHR85:UsbSerial:6.1.0'
implementation 'com.github.mik3y:usb-serial-for-android:2.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
apply plugin: 'com.google.gms.google-services'
通知服务几乎可用于所有设备,但 在Android PC上无法正常工作。我该怎么办?
PC android版本:7.1.2 型号:rk3288
在configureFCM()
中,所有手机和平板电脑都说"success"
但android pc无法访问"addOnCompleteListener"
或"addOnFailureListener"
或捕获动作只是通过方法。我该如何解决这个问题?