小型网站项目策划书,dw建设个人网站步骤,怎样提升网站访问量,wordpress公众号涨粉集成FCM官方文档
Firebace主页面
将 Firebase 添加到您的 Android 应用
1、进入Firebace页面#xff0c;创建自己的项目 2、点击自己创建好的项目#xff0c;在右侧选择Cloud Messaging 3、点击Android去创建 google-services.json 4、将下载的 google-services.json 文件…集成FCM官方文档
Firebace主页面
将 Firebase 添加到您的 Android 应用
1、进入Firebace页面创建自己的项目 2、点击自己创建好的项目在右侧选择Cloud Messaging 3、点击Android去创建 google-services.json 4、将下载的 google-services.json 文件移到您的模块应用级根目录中 5、添加相关SDK(根据自己AGP版本去添加对应的SDK版本否则可能会编译失败)
将该插件作为依赖项添加到您的项目级 build.gradle 文件中
根级项目级Gradle 文件 (project/build.gradle)
plugins {// ...// Add the dependency for the Google services Gradle pluginid com.google.gms.google-services version 4.4.2 apply false}
然后在模块应用级 build.gradle 文件中同时添加要在您的应用中使用的 google-services 插件和任何 Firebase SDK
模块应用级Gradle 文件 (project/app-module/build.gradle)
plugins {id com.android.application// Add the Google services Gradle pluginid com.google.gms.google-services...
}dependencies {// Import the Firebase BoMimplementation platform(com.google.firebase:firebase-bom:33.6.0)// TODO: Add the dependencies for Firebase products you want to use// When using the BoM, dont specify versions in Firebase dependenciesimplementation com.google.firebase:firebase-analytics// Add the dependencies for any other desired Firebase products// https://firebase.google.com/docs/android/setup#available-librariesimplementation com.google.firebase:firebase-messaging:24.0.3
}
重写FirebaseMessagingService
public class MyFirebaseMessagingService extends FirebaseMessagingService {private static final String TAG MyFirebaseMessagingService.class.getSimpleName();/*** 监听推送的消息* 三种情况* 1通知时* 当应用处于前台的时候推送的消息会走onMessageReceived方法处于后台时走系统托盘。* 2数据时* 当应用处于前、后台的时候会走onMessageReceived方法。* 3通知且携带数据* 当应用处于前台的时候推送的消息会走onMessageReceived方法处于后台时通知走系统托盘数据走Intent 的 extra 中点击通知栏后。*/Overridepublic void onMessageReceived(NonNull RemoteMessage message) {}/*** 当有新的Firebase token 时的回调* 第一次安装app 获取到的 pushtoken*/Overridepublic void onNewToken(NonNull String token) {//token 传递给后端//在Firebase控制台测试push的时候需要将token配置进去Logger.i(TAG, onNewToken token);}}
serviceandroid:namecom.xx.xx.push.fcm.MyFirebaseMessagingServiceandroid:exportedfalseintent-filteraction android:namecom.google.firebase.MESSAGING_EVENT //intent-filter/service
完成以上工作就可以正常接收到消息了
注意系统设置中需要开启通知权限
控制台调试
进入Firebase Messaging页面点击制作首个宣传活动 将设备上生成的token添加进去 问题
如果杀进程后接收不到FCM消息 方法1:进入系统设置-找到自己的应用-找到电池-点进去-将受限制改成不受限制或者优化 方法2:进入系统设置-电池-后台使用限制-自定运行应用程序-找到自己的应用选上 设置后进程被杀进后会被系统拉起 方法1设置完后去设置查看方法2也被设置上了反之亦然
问题相关文档
stackoverflow
阿里云