0

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

4

2 回答 2

0

我用上面的代码注册

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);


        }
    }

希望这会有所帮助。

于 2012-04-14T03:21:15.887 回答
-1

我们无法在模拟器中测试 C2DM。因为它需要设备中的市场应用程序才能注册 C2DM 服务器。并且还需要登录市场应用程序。这样应用程序才能完美运行。

于 2012-04-14T02:44:30.990 回答