Я пытаюсь открыть веб-страницу в приложении для Android, схема URL-адресов немного особенная, она должна открывать 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);
}
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
Есть ли способ добиться этого?
Попробуй это
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");
Спасибо за ответ, но он не отличается от моего кода. Также URL-адрес должен быть
about:reader?url=http://example.com, проблема в том, что частьabout:readerобрабатывается неправильно, я думаю.