2016-11-09 195 views
0
//Here is my code of FIREBASEINSTANCEIDSERVICE 

// reg_id不生成 //沒有ID我無法發送通知。應用程序運行沒有任何錯誤。 //我不明白爲什麼會發生,我是初學者,這就是爲什麼我沒有得到。請解決這個問題。使用Firebase發送推送通知時不生成註冊ID

package com.fication.noti.mynotification.service; 

import android.content.Intent; 
import android.content.SharedPreferences; 
import android.support.v4.content.LocalBroadcastManager; 
import android.util.Log; 

import com.fication.noti.mynotification.app.Config; 
import com.google.firebase.iid.FirebaseInstanceId; 
import com.google.firebase.iid.FirebaseInstanceIdService; 

/** 
* Created by lenovo on 05/11/2016. 
*/ 
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { 

    private static final String TAG =   MyFirebaseInstanceIDService.class.getSimpleName(); 

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

     // Saving reg id to shared preferences 
     storeRegIdInPref(refreshedToken); 

     // sending reg id to your server 
     sendRegistrationToServer(refreshedToken); 

     // Notify UI that registration has completed, so the progress indicator can be hidden. 
     Intent registrationComplete = new Intent(Config.REGISTRATION_COMPLETE); 
     registrationComplete.putExtra("token", refreshedToken); 
     LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); 
    } 

    private void sendRegistrationToServer(final String token) { 
     // sending gcm token to server 
     Log.e(TAG, "sendRegistrationToServer: " + token); 
    } 

    private void storeRegIdInPref(String token) { 
     SharedPreferences pref = getApplicationContext().getSharedPreferences(Config.SHARED_PREF, 0); 
     SharedPreferences.Editor editor = pref.edit(); 
     editor.putString("regId", token); 
     editor.commit(); 
    } 
} 

回答

0

您是否在應用程序類中初始化了Firebase?

FirebaseApp.initializeApp(this);