将在eclipse中支持通过GCM推送通知

时间:2016-05-09 14:00:31

标签: android eclipse push-notification google-cloud-messaging

我正在使用eclipse IDE进行开发。我在项目中遵循了很多教程并实现了推送通知,但我没有获得GCM注册ID,所以我的问题是: eclipse 是否支持推送通知?

以下是代码段;如果您需要更清晰,请在下面评论。

        registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    Log.v("testing", "testing");
    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    Log.v("regId", regId);
    // Check if regid already presents
    if (regId.equals("")) {
        // Registration is not present, register now with GCM
        Log.v("registerd","am here");

        GCMRegistrar.register(this, 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;
            Log.v("hello","am here");

            mRegisterTask = new AsyncTask<Void, Void, Void>() {
                @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;
                }

            };
            mRegisterTask.execute(null, null, null);
        }

2 个答案:

答案 0 :(得分:5)

无论您使用什么IDE,推送通知都会有效,但我有两条建议:

  1. 您需要将项目迁移到Android Studio以获得更好的支持。
  2. 您的GCM注册库GCMRegistrar太旧了。您需要获取最新版本,结帐here
  3. 希望这有助于:)

答案 1 :(得分:0)

最后通过使用以下教程获得答案.. link