почему GCM не дает push-уведомления в устройстве Android?

Я новичок на Android и делаю демо-приложение для gcm push-уведомлений.

Я разработал весь этот код, и push-уведомления GCM поступают на устройства в моей среде, но когда я тестирую этот код в другом сетевом устройстве, он получает регистрационный идентификатор, но серверная сторона получает несоответствующий ответ идентификатора отправителя при отправке сообщений в облако. Мой код приведен ниже:

        checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID");

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);

    setContentView(R.layout.activity_push_android);
    mDisplay = (TextView) findViewById(R.id.display);

    final String regId = GCMRegistrar.getRegistrationId(this);
    Log.i(TAG, "registration id =====  " + regId);

    if (regId.equals("")) {
        GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
    } else {
        // Device is already registered on GCM
        if (GCMRegistrar.isRegisteredOnServer(this)) {
            // Skips registration.
            Toast.makeText(getApplicationContext(),
                    "Already registered with GCM", Toast.LENGTH_LONG)
                    .show();
        } else {
            // Try to register again, but not in the UI thread.
            // It's also necessary to cancel the thread onDestroy(),
            // hence the use of AsyncTask instead of a raw thread.
            // final Context context = this;
            mRegisterTask = new AsyncTask() {

                @Override
                protected Void doInBackground(Void... params) {
                    // Register on our server
                    // On server creates a new user
                    // ServerUtilities.register(context, name, email,
                    // regId);
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    mRegisterTask = null;
                    mDisplay.setText("ffffff        " + regId);
                }

            };
            mRegisterTask.execute(null, null, null);
        }
    }
    // regId = GCMRegistrar.getRegistrationId(this);
    mDisplay.setText("ffffff        " + regId);
    Log.i(TAG, "registration id =====!!!!  " + regId);
}

private void checkNotNull(Object reference, String name) {
    if (reference == null) {
        throw new NullPointerException(getString(R.string.error_config,
                name));
    }
}

@Override
protected void onPause() {
    super.onPause();
    GCMRegistrar.unregister(this);
}
  }

получатель:

public GCMIntentService() {
    super(CommonUtilities.SENDER_ID);

}

private static final String TAG = "===GCMIntentService===";

@Override
protected void onRegistered(Context arg0, String registrationId) {
    Log.i(TAG, "Device registered: regId = " + registrationId);
}

@Override
protected void onUnregistered(Context arg0, String arg1) {
    Log.i(TAG, "unregistered = " + arg1);
}

@Override
protected void onMessage(Context arg0, Intent message) {
    Bundle extras = message.getExtras();

    for (String key : extras.keySet()) {
        Log.d(getClass().getSimpleName(),
                String.format("onMessage: %s=%s", key,
                        extras.getString(key)));

        Toast.makeText(getApplicationContext(), "hii", Toast.LENGTH_LONG)
                .show();
    }
    Log.i(TAG, "new message= ");

    // ///////////////////

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher,
            (CharSequence) message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context,
            PushAndroidActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
    notification.setLatestEventInfo(context, title, (CharSequence) message,
            intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

@Override
protected void onError(Context arg0, String errorId) {
    Log.i(TAG, "Received error: " + errorId);
}

@Override
protected boolean onRecoverableError(Context context, String errorId) {
    return super.onRecoverableError(context, errorId);
}
  }

Этот код успешно дал мне регистрационный идентификатор. Чтобы проверить мой код, я выполнил Java-класс для отправки сообщения в облако. Этот Java-класс:

  public static void main(String args[]) {

    try {

        Sender sender = new Sender(
                "my server api");

        ArrayList devicesList = new ArrayList();

        devicesList
                .add("reg id");
        // devicesList.add("reg id");

        // Use this line to send message without payload data
        // Message message = new Message.Builder().build();

        // use this line to send message with payload data
        Message message = new Message.Builder()
                .collapseKey("1")
                .timeToLive(3)
                .delayWhileIdle(true)
                .addData("message",
                        "this text be will be seen in notification bar!!")
                .build();

        // Use this code to send to a single device
        // Result result = sender
        // .send(message,
        // "APA91bGiRaramjyohc2lKjAgFGpzBwtEmI8tJC30O89C2b3IjP1CuMeU1h9LMjKhmWuZwcXZjy1eqC4cE0tWBNt61Kx_SuMF6awzIt8WNq_4AfwflaVPHQ0wYHG_UX3snjp_U-5kJkmysdRlN6T8xChB1n3DtIq98w",
        // 1);

        // Use this for multicast messages
        MulticastResult result = sender.send(message, devicesList, 1);
        sender.send(message, devicesList, 1);

        System.out.println(result.toString() + "\n");
        if (result.getResults() != null) {
            int canonicalRegId = result.getCanonicalIds();
            if (canonicalRegId != 0) {
                System.out.println(canonicalRegId);
            }
        } else {
            int error = result.getFailure();
            System.out.println(error);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
  }

Теперь проблема в том, что я не получаю никаких push-уведомлений или сообщений в журнале cat. Заранее спасибо за помощь. Manifest:

SDK Android: minSdkVersion = "8" Android: targetSdkVersion =»16 "/>










    
        
            

            
        
    

    
        
            
            

            
        
    

    

Ответы на вопрос(2)

Ваш ответ на вопрос