C2DM 注册失败,因为相同的auth_key



我目前正在笔记本上测试我的c2dm应用程序。我使用两个模拟器来测试服务器和客户端设备之间的通信。问题是第二个设备无法注册到我的服务器,因为它与第一个设备具有相同的 [auth_token]。(他们都有不同的有效Gmail帐户)。有没有人可以帮忙,所以我可以使用两个(或更多)具有不同 [auth_token] 的模拟器?之前谢谢..:)

我使用了上面的代码进行注册

SharedPreferences wmbPreference1 = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
boolean isRegistrationId = wmbPreference1.getBoolean("RegistrationId", true);
    if(isRegistrationId)
       {
            Log.w("C2DM", "start registration process");
             SharedPreferences.Editor editor = wmbPreference1.edit();
             editor.putBoolean("RegistrationId", false);
              editor.commit();
              Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.putExtra("app",PendingIntent.getBroadcast(put here your current acitivity.this, 0, new Intent(), 0));`

     intent.putExtra("sender", "xyz@gmail.com");//put here different gmail id 
                    startService(intent);
                       }

并使用下面的课程来接收注册 ID。

public class C2DMRegistrationReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.w("C2DM", "Registration Receiver called");
        if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
            Log.w("C2DM", "Received registration ID");
            final String registrationId = intent
                    .getStringExtra("registration_id");
            String error = intent.getStringExtra("error");
            Log.w("C2DM", "Received registration ID"+registrationId);
            Log.d("C2DM", "dmControl: registrationId = " + registrationId
                    + ", error = " + error);
            String deviceId = Secure.getString(context.getContentResolver(),
                    Secure.ANDROID_ID);
            Log.w("C2DM", "Received device ID"+deviceId);

        }
    }

希望这会有所帮助。

我们无法在模拟器中测试 C2DM。因为它需要设备中的市场应用程序才能注册C2DM服务器。此外,市场应用程序也需要登录。因此,该应用程序将完美运行。

相关内容

最新更新