1

私の GCM アプリは、同じデバイスに対して複数の登録を生成します。これを検索しましたが、解決策が見つかりませんでした。

これが私の主な活動です::

public void onCreate(Bundle savedInstanceState) {
    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, "952039800261");
    } else {
      Log.v(TAG, "Already registered");

    }}

そして、これは私の onRegistered() メソッドです::

protected void onRegistered(Context arg0, final String regId) {

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
// sets the app name in the intent
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", senderId);
startService(registrationIntent);


   // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.ludlowcastle.co.in/moksha/register.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("regId", regId));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

サーバー上の同じデバイスに対して約 5,000 の登録 ID があります。

4

1 に答える 1

0

無限ループに登録しています。

私はクラスを使用しませんが、これらの行と同じ ことを行うGCMRegistrarと確信しています:GCMRegistrar.register(this, "952039800261");

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
// sets the app name in the intent
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", senderId);
startService(registrationIntent);

私のアプリでは、これらの 4 行は呼び出しonCreateではなくメイン アクティビティのメソッドにありGCMRegistrarます。

onRegistered呼び出されると、これは登録が成功し、登録 ID があることを意味します。このメソッドでは再登録を求めているため、Google に新規登録リクエストが送信され、次の登録が成功したときにこのメソッドが再度呼び出されます。呼び出しごとに異なる登録 ID を取得しているのか、それとも同じ ID を取得しているのかはわかりませんが、前述の 4 行を削除するだけでonRegistered問題は解決します。

于 2013-03-17T15:25:48.090 に答える