Java 在Google Glass浏览器中打开本地html文件
我的res/raw中有一个HTML文件,我想在Google glass浏览器中查看 建议复制到共享存储或使用WebView 我似乎不能像浏览器那样使用触摸板使WebView滚动,这使得它对我的目的毫无用处 我尝试将文件复制到共享存储(即/mnt/sdcard/Android/data/my.namespace/files/page.html)并使用Java 在Google Glass浏览器中打开本地html文件,java,android,google-glass,google-gdk,Java,Android,Google Glass,Google Gdk,我的res/raw中有一个HTML文件,我想在Google glass浏览器中查看 建议复制到共享存储或使用WebView 我似乎不能像浏览器那样使用触摸板使WebView滚动,这使得它对我的目的毫无用处 我尝试将文件复制到共享存储(即/mnt/sdcard/Android/data/my.namespace/files/page.html)并使用 Intent i = new Intent(Intent.ACTION_VIEW); File file = new File(f.getAbsol
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);
但我有一个例外:
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 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中启动浏览器的活动是:
i.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity")
由于出现以下错误消息:
“ActivityNotFoundException:找不到可处理意图的活动”
,因此需要定义必须打开意图的活动,在本例中为浏览器
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中启动浏览器的活动是:
i.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity")
Glass上没有股票android浏览器,因此我得到
ActivityNotFoundException:找不到明确的活动类{com.google.android.browser/com.android.browser.browser.BrowserActivity}
在对GlassBrowser.apk进行了一些挖掘和反编译后,我发现所需的活动是I.setClassName(“com.google.Glass.browser”,“com.google.glass.browser.WebBrowserActivity”)
。感谢您为我指明了正确的方向。感谢Ben,我支持这是导致异常的原因,但希望tp将来能与google glass一起发挥更大的作用。只需提一下,如果您想打开一个在线网站,您可以执行intent=newintent(intent.ACTION\u视图);intent.setData(Uri.parse(url));intent.setClassName(“com.google.glass.browser”、“com.google.glass.browser.WebBrowserActivity”);
股票android浏览器在glass上不可用,因此我得到ActivityNotFoundException:无法找到显式活动类{com.google.android.browser/com.android.browser.BrowserActivity}
在对GlassBrowser.apk进行了一些挖掘和反编译之后,我发现所需的活动是i.setClassName(“com.google.glass.browser”,“com.google.glass.browser.WebBrowserActivity”)
。感谢你为我指明了正确的方向。谢谢你,本,我支持这是导致异常的原因,但希望tp将来能与google glass一起发挥更大的作用。只需提到,如果你想打开一个在线网站,你可以做intent=new intent(intent.ACTION\u VIEW);intent.setData(Uri.parse(url));intent.setClassName(“com.google.glass.browser”、“com.google.glass.browser.WebBrowserActivity”);