duanmu6231 2018-10-25 08:29
浏览 41

android app登录android 4.0.3但不登录android 6.1

i developed a simple app using android 4.0.3. The problem im having is the login screen. It is logging in using android 4.0.3 version but when i install it on android 6.1 it refuses to login in. Im failing to see where the problem lies.

heres is the source code for the login screen. Its just showing an error saying check your connection settings of which that is an error message i provided

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;

    }


}

}

  • 写回答

1条回答 默认 最新

  • douruhu4282 2018-10-25 10:26
    关注

    Have you given runtime permission?

    If no then give all the necessary permissions to enable the app to fire a HTTP request.

    To set runtime permission, you can go through:

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

    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数