デバイスのブラウザでローカルの html ファイルを読み込もうとしています。WebView を使用してみましたが、すべてのデバイスで機能するとは限りません。
//WebView method that didnt work for all devices
WebView w = new WebView(this);
w.getSettings().setJavaScriptEnabled(true);
w.loadUrl("file:///android_asset/my.html");
setContentView(w);
だから私はhtmlビューアでファイルを開くこの方法を試しましたが、読み込もうとしているhtmlにはjavascriptが必要なため機能しません
// html view that also doesnt work
Intent i = new Intent();
//i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this is optional
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(myFile), "text/*");
startActivity(i);
追加するなど、これを行うさまざまな方法を試して、少なくとも1日は周りを見回しました
i.addCategory(Intent.CATEGORY_BROWSABLE);
i.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
しかし、彼らは次のようなエラーを返します
Unable to start activity android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] typ=text/html }
と
Unable to start activity android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.browser/com.android.browser.BrowserActivity}; have you declared this activity in your AndroidManifest.xml?
これを行うための最良の方法は、アセットフォルダーから直接htmlをロードすることです。これは、WebViewを使用して非常に簡単であることを知っていますが、Galaxy NexusやNexus 7などのデバイスでは機能しないと言ったように、機能しますkindle fire や kindle hd などのデバイス向けです。
しかし、現在私が使用している方法は、アセットフォルダーから外部ストレージに保存し、そこからファイルを取得してインテントを介してロードすることですが、これは JavaScript の問題のために機能しません。助言がありますか?ありがとう