the*_*oid 9 android android-emulator android-intent android-browser
我想专门为给定的URL运行默认的Android浏览器.我正在使用此代码:
Intent i = new Intent();
i.setAction("android.intent.action.VIEW");
i.addCategory("android.intent.category.BROWSABLE");
i.setClassName("com.google.android.browser", "com.android.browser.BrowserActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
Unable to find explicit activity class {
com.google.android.browser/com.android.browser.BrowserActivity};
have you declared this activity in your AndroidManifest.xml?
Run Code Online (Sandbox Code Playgroud)
我也尝试过包过滤意图:
i.setPackage("com.google.android.browser");
Run Code Online (Sandbox Code Playgroud)
而不是setClassName,但无济于事:
No Activity found to handle Intent { act=android.intent.action.VIEW
cat=[android.intent.category.BROWSABLE]
dat=http://www.google.com/ flg=0x10000000 pkg=android }
Run Code Online (Sandbox Code Playgroud)
我也尝试过添加<uses-library android:name="com.google.android.browser" />清单.
我在这里错过了什么吗?
PS:我对使用不感兴趣,startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")))因为它会列出浏览的所有选项Intent.
请注意默认浏览器可以被覆盖,并且它并不总是内置的浏览器应用程序,它可以是例如Opera Mini.
你需要这样做:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("http://www.google.com");
intent.setData(data);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
小智 6
我用它,没关系.
intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
Run Code Online (Sandbox Code Playgroud)
我想你知道什么是错的.:)
| 归档时间: |
|
| 查看次数: |
11241 次 |
| 最近记录: |