Android Studio隐含意图基本问题
我正在学习安卓基础02.3:隐含意图,我遵循这些步骤,但无法处理意图。 这是我写的:Android Studio隐含意图基本问题,android,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.
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!
我尝试的是:
当我下载正式项目并构建时,它可以正常工作。
当我删除“如果”时,它起作用:
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);
}
问题是,为什么会发生这种情况?您使用什么设备进行测试?您是否尝试使用调试器查看发生了什么?