我正在 android studio 4.0 中尝试 codelabs 的一些代码,并在应用程序中使用以下代码:
String uri = uritext.getText().toString();//uritext is an editText view
Uri webpage = Uri.parse(uri);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if(intent.resolveActivity(getApplicationContext().getPackageManager())!=null){
startActivity(intent);
}
else {
Log.d("implicitintent:","cant handle this implicit intent!");
Toast toast = Toast.makeText(MainActivity.this,"cant open website:" + uri,Toast.LENGTH_SHORT);
toast.show();
}
Run Code Online (Sandbox Code Playgroud)
我已经在两个不同的 AVD 中尝试了上述代码,当我尝试在按钮单击事件中执行上述代码时,它们都显示了 toast 消息。这意味着resolveActivity() 返回一个null。我找不到任何可能的原因,因为我发现两个 AVD 上都安装了 google chrome。Logcat 显示以下几行:
2020-07-14 17:39:05.829 392-392/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-07-14 17:39:08.229 395-395/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open …Run Code Online (Sandbox Code Playgroud)