我的 res/raw 中有一个 HTML 文件,我想在 Google glass 浏览器中查看该文件。
This answer建议复制到共享存储或使用 WebView。
我似乎无法像浏览器那样使用触摸板使 WebView 滚动,这使得它对我的目的毫无用处。
我尝试将文件复制到共享存储(即/mnt/sdcard/Android/data/my.namespace/files/page.html)并使用
Intent i = new Intent(Intent.ACTION_VIEW);
File file = new File(f.getAbsolutePath());
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
i.setDataAndType(Uri.fromFile(file),mimetype);
但我得到了这个异常(exception):
03-18 17:58:53.338: E/AndroidRuntime(5315): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/Android/data/my.namespace/files/page.html typ=text/html }
我已经使用 adb shell 检查过,文件位于该位置。有什么想法为什么这可能不起作用吗?这是玻璃特有的问题吗?
谢谢
最佳答案
由于您收到此错误消息:“ActivityNotFoundException:找不到处理 Intent 的 Activity”
,因此您需要定义哪个 Activity 必须打开您的 Intent,在本例中为浏览器。
Intent i = new Intent(Intent.ACTION_VIEW);
File file = new File(f.getAbsolutePath());
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
//you need define this activity to open your html file.
i.setClassName("com.google.android.browser", "com.android.browser.BrowserActivity");
//intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
i.setDataAndType(Uri.fromFile(file),mimetype);
编辑: 在 glass 中启动浏览器的 Activity 是:
i.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity")
关于java - 在Google Glass浏览器中打开本地html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22487736/