سؤال

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

هل كانت مفيدة؟

المحلول

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")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top