[英]GCM Broadcast Receiver differentiate between different requests
我有一個標准的 GCM 廣播接收器。 當我向服務器發出請求時,我會發送我的注冊 ID、用戶名和標題。 當我想從服務器將消息發送回手機時,如何再次確保其為該特定標題? 到目前為止,我看到的所有示例似乎都依賴於 1 個請求。
如果我沒有解釋得足夠好:
用戶 A 在 GCM 服務器上注冊並獲得 gcm 注冊 ID 用戶 A 向服務器發送帶有 gcm 注冊 ID、標題和他們的用戶名的請求。 服務器向用戶發送一條消息。 我如何確保它是針對該特定請求而不是用戶本人?
這是我的廣播接收器
public class GCMBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
Intent update = new Intent("update");
update.putExtra("msg",extras.getString(AppConstants.MSG_KEY));
ComponentName comp = new ComponentName(context.getPackageName(), GCMNotificationIntentService.class.getName());
LocalBroadcastManager.getInstance(context).sendBroadcast(update);
startWakefulService(context, (intent.setComponent(comp)));
Log.d("ONRECEIVEWAKEFUL", "ONRECEIVEWAKEFUL");
Log.d("ONRECEIVEWAKEFULMSG",String.valueOf(extras.getString(AppConstants.MSG_KEY)));
setResultCode(Activity.RESULT_OK);
}
}
我需要設置過濾器還是什么?
編輯這是我從 gcm 服務器接收消息的地方
LocalBroadcastManager.getInstance(this).registerReceiver(onNotice, new IntentFilter("update"));
//Intent msg sent from Broadcast Receiver
String str = getIntent().getStringExtra("msg");
你的后端應該只處理發送消息,但它也應該處理用戶/設備的某種“注冊”,這樣你就可以知道哪個用戶使用哪個設備。 您在設備上收到的registration Id
不考慮用戶- 您需要在后端自己處理它,並以某種方式將注冊 ID 與您的用戶聯系起來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.