Google Cloud Endpoints设置问题

时间:2015-04-12 03:30:46

标签: java android google-app-engine android-studio google-cloud-endpoints

我对Google的云平台完全陌生,而且我在设置Android设备时遇到问题。我正试图关注this tutorial而我正试图用我的Android模拟器测试我的后端。然而,模拟器在20秒后给我this message,而它应该说出我的名字。到目前为止,这是我的代码:

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    buildUI();

    new EndpointsAsyncTask().execute(new Pair<Context, String>(this, "Solomon"));


}

EndpointsAsyncTask.java

public class EndpointsAsyncTask extends AsyncTask<Pair<Context, String>, Void, String> {
private static MyApi myApiService = null;
private Context context;

@Override
protected String doInBackground(Pair<Context, String>... params) {
    if(myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                // options for running against local devappserver
                // - 10.0.2.2 is localhost's IP address in Android emulator
                // - turn off compression when running against local devappserver
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver

        myApiService = builder.build();
    }

    context = params[0].first;
    String name = params[0].second;

    try {
        return myApiService.sayHi(name).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}

@Override
protected void onPostExecute(String result) {
    Toast.makeText(context, result, Toast.LENGTH_LONG).show();
}
}

感谢所有帮助!

编辑:部分问题是我运行的是Endpoints Backend而不是App Engine Servlet后端。但现在我正在接受连接拒绝&#34;我正在运行App Engine Servlet后端。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

经过艰难的几天,我发现问题是我需要将rootUrl从http://10.0.2.2:8080/_ah/api/更改为我的appspot域。现在我收到了Hello World消息。