Home  >  Article  >  Backend Development  >  Android and PHP implement simple login

Android and PHP implement simple login

不言
不言Original
2018-07-13 13:46:503961browse

First effect:


Android and PHP implement simple login

Instructions:

1, use an Android phone or emulator
2, the server supports php
3, simple verification login operation
4, the network request uses the RxEasyHttp open source library, which is an encapsulation of okhttp3, retrofit, it is also possible to use okhttp3 directly
5, used for test login The url is always valid
6. If you need a server, you can use it with me. You can just send a few soft coins. There is no traffic limit or space limit.

Server-side php file

Android-side XML layout file





    

    

    



Android-side java code implementation

public class MainActivity extends AppCompatActivity {

    String loginUrl = "http://soyoyo.esy.es/login.php";

    EditText etName;
    EditText etPwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        etName  = findViewById(R.id.etName);
        etPwd = findViewById(R.id.etPwd);

    }

    // 点击button后执行
    public void doLogin(View view){
        login(etName.getText().toString(),etPwd.getText().toString());
    }

    private void login(String name,String pwd){
        EasyHttp.post(loginUrl)
                .baseUrl(url)
                .params("loginName",name)
                .params("loginPwd", pwd)
                .execute(new CallBack() {

                    @Override
                    public void onStart() {
                        System.out.println("------onStart------");
                    }

                    @Override
                    public void onCompleted() {
                        System.out.println("------onCompleted------");
                    }

                    @Override
                    public void onError(ApiException e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(String s) {
                        System.out.println("------onSuccess------" + s);
                        Toast.makeText(MainActivity.this,s,Toast.LENGTH_SHORT).show();
                    }
                });
    }

}

The above is the entire content of this article, I hope it will be useful to Everyone’s learning is helpful. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

php How to implement random numbers and letters verification code code

php tips how to cleverly avoid Some bad code in PHP programs

The above is the detailed content of Android and PHP implement simple login. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn