java - 在Google Glass浏览器中打开本地html文件

标签 java android google-glass google-gdk

我的 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/

相关文章:

java - 使用 ParseInt 从命令行转换字符串并分配绘制的 g2 图形的列和行

java - 更有效地从 Jar 中提取文件

java - ListView 未按预期生成

android - Android 中的广播组

google-glass - 在 Fastboot 中看到 GLASS 时遇到问题

google-mirror-api - 设置时间轴项目的视频附件尺寸

android - 如何在使用 CardScrollView 时有不同的上下文语音命令菜单?

java - 有没有办法可以在 Controller 类而不是构造函数中创建 JavaFX GUI?

java - 使用 Scanner 和 nextLine 结束程序

android - 从应用程序中的任何位置访问变量(Android)