我知道Java中已经有一个检查网址的工具了。但我不知道为什么这个逻辑不起作用。即使输入正确,警告消息也不会消失。谢谢。
@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(""));
}发布于 2019-02-01 14:48:37
在我的项目中,我是这样使用的:
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();
}发布于 2019-02-01 14:34:24
将您的支票更改为from
(uri.startsWith("http:")&&!uri.equals(""))到这个
(uri.startsWith("http"))首先,url可以以http或https开头,因此上面的检查不包括第二种情况。其次,如果startsWith已经通过,则不需要检查!uri.equals("")
https://stackoverflow.com/questions/54474060
复制相似问题