0

I know there's already a tool to check web address in Java. But I don't know why this logic does not work. The alert message does not go away even if the input is right. Thanks.

@Override
public void onClick(View view) {
    if(checkInput()){
        String email = getResources().getString(R.string.email);
        Intent i = new Intent();
        i.setData(Uri.parse("mailto:"));
        startActivity(Intent.createChooser(i, "Send mail..."));
    }else{
        AlertDialog alert = new AlertDialog.Builder(getContext()).create();
        alert.setMessage(getResources().getString(R.string.valid_input));
        alert.show();
    }

}

public boolean checkInput(){

        return (uri.startsWith("http:")&&!uri.equals(""));
}
g_studio
  • 43
  • 6

2 Answers2

0

Change your check to from

(uri.startsWith("http:")&&!uri.equals(""))

to this

(uri.startsWith("http"))

Firstly, url can start with either http or https, so your check above does not cover the second case. Secondly, if startsWith already passed, there is no need to check !uri.equals("")

Bach Vu
  • 2,298
  • 1
  • 15
  • 19
0

In my project i use like this :

    if (CheckInternetConection.isInternetConnection(SplashScreenActivity.this)) {
 Intent emailIntent = new Intent(Intent.ACTION_SEND);
                                    emailIntent.setType("vnd.android.cursor.dir/email");
                                    String to[] = {"bugfreeRam@gmail.com"};
                                    emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
                                    emailIntent.putExtra(Intent.EXTRA_STREAM, path);
                                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Database File");
                                    startActivity(Intent.createChooser(emailIntent, "Send email..."));
 } else {

                                    new SweetAlertDialog(SplashScreenActivity.this)
                                            .setTitleText("Alert!")
                                            .setContentText(getResources().getString(R.string.app_connection))
                                            .show();
                                }
bugfreerammohan
  • 1,471
  • 1
  • 7
  • 22