2017-03-29 246 views
1

我使用FCM發送消息給客戶端(android),但我會有很多客戶端android,並且我只想發送消息給一個設備而不是所有人。我怎樣才能做到這一點?現在,當我發送消息我送大家Android FCM發送消息給用戶

+0

使用php /任何其他後端語言運行腳本,並通過與db同步來限制接收器。 –

回答

1

給出。如果你有「FCM註冊令牌」的所有用戶,你可以發送郵件到單個設備或用戶使用該用戶FCM註冊令牌

1

信息發送到一個設備沒有每一個

當您從客戶端應用程序註冊的FCM,您將收到該設備的令牌。您可以將其傳遞到服務器並將其保存在那裏。稍後,您可以使用該特定設備令牌將FCM消息發送到該設備。

它返回FCM標記的代碼片段如下

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


public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { 

    private static final String TAG = "MyFirebaseIIDService"; 

    /** 
    * Called if InstanceID token is updated. This may occur if the security of 
    * the previous token had been compromised. Note that this is called when the InstanceID token 
    * is initially generated so this is where you would retrieve the token. 
    */ 
    // [START refresh_token] 
    @Override 
    public void onTokenRefresh() { 
     // Get updated InstanceID token. 
     String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(TAG, "Refreshed token: " + refreshedToken); 

     // If you want to send messages to this application instance or 
     // manage this apps subscriptions on the server side, send the 
     // Instance ID token to your app server. 
     sendRegistrationToServer(refreshedToken); 
    } 
    // [END refresh_token] 

    /** 
    * Persist token to third-party servers. 
    * 
    * Modify this method to associate the user's FCM InstanceID token with any server-side account 
    * maintained by your application. 
    * 
    * @param token The new token. 
    */ 
    private void sendRegistrationToServer(String token) { 
     // TODO: Implement this method to send token to your app server. 
    } 
} 

看到官方doc