2

I have an HTML file in my res/raw that I want to view in the Google glass browser.

This answer suggests either copying to shared storage or using a WebView.

I cant seem to make the WebView scroll using the touchpad in the same way the browser does, which renders it useless for my purposes.

I tried copying the file to shared storage (i.e. /mnt/sdcard/Android/data/my.namespace/files/page.html) and using

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);

but I get this 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 }

I've checked with adb shell and the file is at that location. Any ideas why this may not be working? Is it a glass specific issue?

Thanks

Community
  • 1
  • 1
Ben
  • 1,767
  • 16
  • 32

1 Answers1

4

since you have this error message: "ActivityNotFoundException: No Activity found to handle Intent", you need to define what activity must open your intent, in this case the browser.

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);

EDIT: The activity to start the browser in glass is:

i.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity")
Ben
  • 1,767
  • 16
  • 32
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • 1
    The stock android browser isn't available on Glass so I get `ActivityNotFoundException: Unable to find explicit activity class {com.google.android.browser/com.android.browser.BrowserActivity}` after a bit of digging and decompiling of GlassBrowser.apk i've found the required activity is `i.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity")`. Thanks for pointing me in the right direction. – Ben Mar 19 '14 at 10:06
  • Thank you Ben, I suppsed that was the cause of the exception but hope tp work even more with google glass in the future. – Jorgesys Mar 19 '14 at 15:43
  • Just to mention that if you want to open an online website, you can do `intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); intent.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity");` – Fernando Gallego Nov 18 '14 at 14:43