2017-02-18 49 views
1

我刚刚在我的webview应用中实施了FCM推送通知,当我在模拟器上运行我的应用并从FCM控制台发送通知时,我的应用将在我的应用在后台运行时收到通知。但是,当我构建并将apk文件安装到我的小工具上时,同样的通知永远不会在我的小工具上收到。如何解决这个问题?未在小工具上收到FCM

package com.example.intawebapp.activity; 

import android.util.Log; 

import com.google.firebase.iid.FirebaseInstanceId; 
import com.google.firebase.iid.FirebaseInstanceIdService; 

public class FirebaseIDService extends FirebaseInstanceIdService { 
    private static final String TAG = "FirebaseIDService"; 

    @Override 
    public void onTokenRefresh() { 
     // Get updated InstanceID token. 
     String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(TAG, "Refreshed token: " + refreshedToken); 

     // TODO: Implement this method to send any registration to your app's servers. 
     sendRegistrationToServer(refreshedToken); 
    } 

    private void sendRegistrationToServer(String token) { 
     // Add custom implementation, as needed. 
    } 
} 

package com.example.intawebapp.activity; 

    import android.util.Log; 

    import com.google.firebase.messaging.FirebaseMessagingService; 
    import com.google.firebase.messaging.RemoteMessage; 

     public class MyFirebaseMessagingService extends FirebaseMessagingService { 
     private static final String TAG = "FCM Service"; 
     @Override 
     public void onMessageReceived(RemoteMessage remoteMessage) { 
      // TODO: Handle FCM messages here. 
      // If the application is in the foreground handle both data and notification messages here. 
      // Also if you intend on generating your own notifications as a result of a received FCM 
      // message, here is where that should be initiated. 
      Log.d(TAG, "From: " + remoteMessage.getFrom()); 
      Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 
     } 
    } 

和清单

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.intawebapp"> 

    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".activity.MainActivity" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme.NoActionBar"> 
     </activity> 
     <activity 
      android:name=".activity.SplashActivity" 
      android:theme="@style/SplashTheme"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <service android:name=".activity.MyFirebaseMessagingService"> 
      <intent-filter> 
       <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
      </intent-filter> 
     </service> 


     <service android:name=".activity.FirebaseIDService"> 
      <intent-filter> 
       <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
      </intent-filter> 
     </service> 
    </application> 

</manifest> 
+0

我把后我的小工具可以收到通知FCM控制台中的SHA 1 – rex

回答

0

我的小工具现在可以接收通知我把SHA 1后FCM控制台