Kwa*_*per 7 android uri android-intent
我试图在Android应用程序上打开一个网页,url sheme有点特殊,它必须在阅读器模式下打开一个URL: about:reader?url=example.com
我是这样做的
Uri intentUri = new Uri.Builder().encodedPath("about:reader")
.appendQueryParameter("url", Uri.encode("example.com"))
.build();
// Try to open in Firefox If available or use default
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(intentUri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("org.mozilla.firefox");
try {
getApplicationContext().startActivity(intent);
} catch (ActivityNotFoundException ex) {
intent.setPackage(null);
getApplicationContext().startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
logcat的:
E/AndroidRuntime: FATAL EXCEPTION: main
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=about:reader?url=http://example.com
有没有办法实现这个目标?
Kha*_*ela -1
尝试这个
final String pdf_url = "http://example.com"; // DON'T forget http{s}:// prefix.
// Try to open in Firefox If available or use default
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pdf_url));
// You can also using Google viewer
// intent.setDataAndType(Uri.parse( "http://docs.google.com/viewer?url=" + pdf_url), "text/html");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("org.mozilla.firefox");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
317 次 |
| 最近记录: |