我正在尝试开发一个应用程序,用于保存和存储用户的电子邮件和密码。我遵循Google云平台教程,但我仍然无法找到将我的应用程序(使用Android Studio制作)连接到Google App Engine工具的方法
这是我的LoginActivity java类
公共类LoginActivity扩展了AppCompatActivity {
public class MyTask extends AsyncTask<Pair<Context, String>, Void, String>
{
LoginApi loginApiService = null;
private Context context;
AutoCompleteTextView email = (AutoCompleteTextView) findViewById(R.id.txt_email);
String email2 = email.getText().toString();
TextView senha = (TextView) findViewById(R.id.txt_password);
String senha2 = senha.getText().toString();
private String userdata;
@SafeVarargs
protected final String doInBackground(Pair<Context, String>... params) {
if (loginApiService == null) { // Only do this once
LoginApi.Builder builder = new LoginApi.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://104.154.208.108:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
// end options for devappserver
loginApiService = builder.build();
}
context = params[0].first;
String name = params[0].second;
try {
return loginApiService.sayHi(email2.getEmail()).execute().getData();
} catch (IOException e) {
return e.getMessage();
}
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(context, result, Toast.LENGTH_LONG).show();
}
}
我不确定IP号码和这一行“loginApiService.sayHi(email2.getEmail())。execute()。getData();”
谢谢!
答案 0 :(得分:0)
如果要连接到高效的服务器,则不必设置根URL,也不必禁用gzip。您的语言环境开发服务器
需要此选项编辑:
请参阅我的示例代码:
if(LOCAL_RUN) { // my local development Server
return new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
.setRootUrl("http://192.168.0.235:8080/_ah/api/") //depends how you have configured your local server
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
} else { // the real App Engine Server
return new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null));
}