无法解析符号

时间:2015-02-18 15:05:58

标签: java android

我尝试使用Google Cloud Messaging。

我跟着上课:

package de.phcom.avs;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import com.google.android.gms.gcm.GoogleCloudMessaging;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GcmRegistrationAsyncTask extends AsyncTask<Void, Void, String> {
private static Registration regService = null;
private GoogleCloudMessaging gcm;
private Context context;

// TODO: change to your own sender ID to Google Developers Console project number, as per instructions above
private static final String SENDER_ID = "131952017954";

public GcmRegistrationAsyncTask(Context context) {
    this.context = context;
}

@Override
protected String doInBackground(Void... params) {
    if (regService == null) {
        Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                // Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
                // otherwise they can be skipped
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                            throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end of optional local run code

        regService = builder.build();
    }

    String msg = "";
    try {
        if (gcm == null) {
            gcm = GoogleCloudMessaging.getInstance(context);
        }
        String regId = gcm.register(SENDER_ID);
        msg = "Device registered, registration ID=" + regId;

        // You should send the registration ID to your server over HTTP,
        // so it can use GCM/HTTP or CCS to send messages to your app.
        // The request to your server should be authenticated if your app
        // is using accounts.
        regService.register(regId).execute();

    } catch (IOException ex) {
        ex.printStackTrace();
        msg = "Error: " + ex.getMessage();
    }
    return msg;
}

@Override
protected void onPostExecute(String msg) {
    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    Logger.getLogger("REGISTRATION").log(Level.INFO, msg);
}
}

他们说:

  • 无法解析符号'注册'
  • 无法解析符号'AndroidHttp'
  • 无法解析符号'AndroidJsonFactory'

等等。 我已下载Google API 19和21。

1 个答案:

答案 0 :(得分:1)

刚刚详述Mena的答案

您可以通过添加以下依赖项来解决此问题:

compile 'com.google.http-client:google-http-client-android:1.22.0'
相关问题