简体   繁体   English

将Google App Engine后端添加到我的应用程序

[英]Adding Google App Engine Backend to my App

I am trying to develop an app that saves and storage Email and Password from an User. 我正在尝试开发一个用于保存和存储用户电子邮件和密码的应用程序。 I followed the Google Cloud Platform Tutorial, but I still can`t figure out a way to connect my app (made using Android Studio) to the Google App Engine tools 我遵循了Google Cloud Platform教程,但是仍然找不到将我的应用程序(使用Android Studio制作)连接到Google App Engine工具的方法

This is my LoginActivity java class 这是我的LoginActivity java类

public class LoginActivity extends AppCompatActivity { 公共类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();
    }
}

I am not sure about the IP number and this line " loginApiService.sayHi(email2.getEmail()).execute().getData(); " 我不确定IP地址和此行“ loginApiService.sayHi(email2.getEmail())。execute()。getData();”

Thanks! 谢谢!

If you want to connect to the productive Server you do not have to set the root Url and you do not have to disable gzip. 如果要连接到生产服务器,则不必设置根Url,也不必禁用gzip。 This options are needed for your locale development server 您的区域设置开发服务器需要此选项

EDIT: 编辑:

See my example Code: 参见我的示例代码:

 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));
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM