firebase 推送教程

申请与添加android项目

这个证书建议使用debug的

Sha1这个是啥呢?

是keysotre的sha1呀,好像在eclipse里直接能查这个debug的sha1. Android studio我没找到。

一般来说windows上debug.keystore在:

C:\Users\Administrator\.android\debug.keystore

进入cmd:

keytool -list -alias androiddebugkey-keystore C:\Users\Administrator\.android\debug.keystore

然后输入密码:直接回车

我的机器上是:E7:5A:3C:53:FB:0C:DE:88:7E:15:A6:E9:D3:20:0A:D5:1D:BA:4B:15

填在上页即可!

 

 

复制配置文件

这里直接下载这个google-services.json

 

 

配置这个google-services.json

 

 

 

 

具体使用

1. First, add rules to your root-level build.gradle file, to include the google-services plugin:

buildscript {
   
// ...
    dependencies {
       
// ...
        classpath
'com.google.gms:google-services:3.0.0'
    }
}

2. Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin:

apply plugin:'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:10.0.1'
  compile 'com.google.firebase:firebase-messaging:10.0.1'
  // Getting a "Could not find" error? Make sure you have
  // the latest Google Repository in the Android SDK manager
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
3. 
    android:name=".MyFirebaseMessagingService">
    
        android:name="com.google.firebase.MESSAGING_EVENT"/>
    
4. 
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_stat_ic_notification"/>


    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent"/>
5. @Override
publicvoid onMessageReceived(RemoteMessage remoteMessage){
    // ...

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG,"From: "+ remoteMessage.getFrom());

    // Check if message contains a data payload.
    if(remoteMessage.getData().size()>0){
        Log.d(TAG,"Message data payload: "+ remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if(remoteMessage.getNotification()!=null){
        Log.d(TAG,"Message Notification Body: "+ remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}

 

6.服务器发送

在左侧:

然后点击发送,记得选择项目

 

 

 

 

测试通过。记得需要,,!手机和Pc

你可能感兴趣的:(工作问题)