首页 > 解决方案 > android 应用程序在 android 4.0.3 上登录,但在 android 6.1 上没有

问题描述

我使用 android 4.0.3 开发了一个简单的应用程序。我遇到的问题是登录屏幕。它正在使用 android 4.0.3 版本登录,但是当我在 android 6.1 上安装它时,它拒绝登录。我看不出问题出在哪里。

这里是登录屏幕的源代码。它只是显示一个错误,说检查您的连接设置,这是我提供的错误消息

public class LoginForm extends AppCompatActivity implements View.OnClickListener {

    //EditText editTextUserName,editTextPassword;
    CardView cardView;
    FButton btnCallAndRegister;
    FButton loginButton;
    FButton btnSms;
    EditText edtUserName;


    private ProgressDialog mProgress;


    String login_url = "https://volleycrud.000webhostapp.com/churchapp/logger.php";
    String gotUserName;
   // ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_form);
        mProgress = new ProgressDialog(LoginForm.this, R.style.MyAlertDialogStyle);
        mProgress.setTitle("Processing...");
        mProgress.setMessage("Logging in Please wait...");
        mProgress.setCancelable(false);
        mProgress.setIndeterminate(true);
        loginButton = (FButton) findViewById(R.id.btnLogin);
        edtUserName = (EditText) findViewById(R.id.edtName);
        cardView = (CardView) findViewById(R.id.cardView);
        btnCallAndRegister = (FButton)findViewById(R.id.btnRegisterCall);
        btnSms = (FButton)findViewById(R.id.smsButton);

        //get the data as json from the server for the branch name

        android.view.animation.Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.swing_up_left);
        cardView.setAnimation(animation);

        btnSms.setOnClickListener(this);


        btnCallAndRegister.setOnClickListener(new View.OnClickListener(){


            @Override
            public void onClick(View v) {

                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:0772325760"));

                if (ActivityCompat.checkSelfPermission(LoginForm.this,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }

                startActivity(callIntent);

            }

        });


        loginButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                if(edtUserName.getText().equals("")){


                    CookieBar.build(LoginForm.this)
                            .setTitle("Error")
                            .setMessage("Please enter a username")
                            .show();


                }

                else {
                    mProgress.show();
                    gotUserName = edtUserName.getText().toString();
                    RequestQueue queue = Volley.newRequestQueue(LoginForm.this);
                    StringRequest request = new StringRequest(Request.Method.POST, login_url, new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {

                            if (response.trim().equals("success")) {

                                mProgress.hide();
                                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                                startActivity(intent);
                                finish();


                            } else {

                                CookieBar.build(LoginForm.this)
                                        .setTitle("Error")
                                        .setMessage("Please check your username")
                                        .show();
                            }

                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {

                            CookieBar.build(LoginForm.this)
                                    .setTitle("Error")
                                    .setMessage("Check Your Connection Settings")
                                    .show();
                            Log.i("My error", "" + error);
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {

                            Map<String, String> map = new HashMap<String, String>();
                            map.put("username", gotUserName);
                            return map;
                        }
                    };

                    queue.add(request);
                }

                }
        });
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){


            case R.id.smsButton:


                AlertDialog dialogSms = new AlertDialog.Builder(LoginForm.this).create();
                dialogSms.setTitle("Send Us A Message");
                dialogSms.setIcon(R.drawable.uficlogo);

                final LinearLayout layout = new LinearLayout(LoginForm.this);
                layout.setOrientation(LinearLayout.VERTICAL);

                final EditText order = new EditText(this);
                order.setHintTextColor(Color.BLUE);
                order.setHint("Enter your Message");

                layout.addView(order);
            dialogSms.setView(layout);

            dialogSms.setButton(Dialog.BUTTON_POSITIVE,"Send SMS",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                            String message = order.getText().toString();

                            if (!message.equals("")) {

                                sendMySms(message);

                            } else {

                                CookieBar.build(LoginForm.this)
                                        .setTitle("Error")
                                        .setMessage("Message Not Sent")
                                        .show();

                            }

                        }

                        private void sendMySms(String message) {
                            // TODO Auto-generated method stub

                            String number = "0772 325 760".trim();
                            Intent intent = new Intent(getApplicationContext(),
                                    LoginForm.class);
                            PendingIntent pi = PendingIntent.getActivity(
                                    getApplicationContext(), 0, intent, 0);
                            SmsManager sms = SmsManager.getDefault();
                            sms.sendTextMessage(number, null, message, pi,
                                    null);

                            CookieBar.build(LoginForm.this)
                                    .setTitle("Success")
                                    .setMessage("Message Sent")
                                    .show();

                        }

                    });

            dialogSms.show();


            break;

    }


}

}

标签: phpandroid

解决方案


你给过runtime许可吗?

如果不是,则授予应用程序触发 HTTP 请求所需的所有权限。

要设置runtime权限,您可以通过:

https://developer.android.com/guide/topics/permissions/overview


推荐阅读