Sat*_*tar 7 notifications android push-notification firebase firebase-cloud-messaging
我在Firebase云消息传递中遇到问题,因为我仅在Firebase中使用过它,直到现在当我从Firebase的Notification压缩器发送通知时,都无法正常工作
我的build.gradle(项目)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
我的build.gradle(App)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.***"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
...
implementation('com.google.android.gms:play-services-base:16.0.1') {
exclude module: 'support-v4'
}
implementation('com.google.android.gms:play-services-maps:16.0.0') {
exclude module: 'support-v4'
}
implementation('com.google.android.gms:play-services-places:16.0.0') {
exclude module: 'support-v4'
}
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-iid:17.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
Run Code Online (Sandbox Code Playgroud)
我的清单就是这样
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.**">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:roundIcon="@drawable/app_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="***"/>
<activity
android:name=".LoginActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service
android:name=".MyFirebaseInstanceIDService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/logo" />
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
这是我在登录中所做的,这是要显示的第一个屏幕
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
refreshedToken = instanceIdResult.getToken();
Log.e("refreshedToken", refreshedToken);
// Do whatever you want with your token now
// i.e. store it on SharedPreferences or DB
// or directly send it to server
}
});
Run Code Online (Sandbox Code Playgroud)
因此,当我启动该应用程序时,出现了刷新令牌,但在Firebase仪表板中什么也没有出现,并且我将软件包名称SHA1添加到了Firebase并下载了google-services.json并添加到了项目级别,并且仍然存在发送通知的问题,手机也不是logcat
怎么解决呢?
| 归档时间: |
|
| 查看次数: |
1153 次 |
| 最近记录: |