我正在学习 Android 基础知识 02.3:隐式意图,我按照步骤操作但无法处理意图。 这是我写的:
public void openWebsite(View view) {
String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}else{
Log.d("ImplicitIntents", "Can't handle this!");
}
}
这是我被告知要写的内容:
public void openWebsite(View view) {
// Get the URL text.
String url = mWebsiteEditText.getText().toString();
// Parse the URI and create the intent.
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
// Find an activity to hand the intent and start that activity.
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this!");
}
}
但我就是跑不动!
D/ImplicitIntents: Can't handle this!
我尝试了什么:
当我下载官方项目并构建时,它可以工作。 当我删除“if”时,它起作用了:
public void openWebsite(View view) {
String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(intent);
}
那么问题来了,为什么会这样?