Created
July 18, 2013 16:16
-
-
Save martindale/6030686 to your computer and use it in GitHub Desktop.
MinSDK version is 15... I think we need 16 if allowing local file access.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="io.soundtrack" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-sdk | |
android:minSdkVersion="15" | |
android:targetSdkVersion="17" /> | |
<application | |
android:hardwareAccelerated="true" | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name="io.soundtrack.YourActivity" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class YourActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
WebView myWebView = (WebView) findViewById(R.id.webview); | |
WebSettings webSettings = myWebView.getSettings(); | |
webSettings.setJavaScriptEnabled(true); | |
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); | |
//webSettings.setAllowFileAccessFromFileURLs(true); //Maybe you don't need this rule | |
webSettings.setAllowUniversalAccessFromFileURLs(true); | |
myWebView.setWebViewClient(new CustomWebViewClient()); | |
myWebView.setWebChromeClient(new WebChromeClient() { | |
@Override | |
public void onConsoleMessage(String message, int lineNumber, | |
String sourceID) { | |
Log.d("Ermagerd", message + " -- From line " | |
+ lineNumber + " of " | |
+ sourceID); | |
} | |
}); | |
// load a file from ./assets/ -- you can put folders directly here as well (i.e., css/ and js/) | |
myWebView.loadUrl("file:///android_asset/index.html"); | |
} | |
private class CustomWebViewClient extends WebViewClient { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
Log.d("Ermagerd", url); | |
view.loadUrl(url); | |
return true; | |
} | |
public void onConsoleMessage(String message, int lineNumber, | |
String sourceID) { | |
Log.d("Ermagerd", message + " -- From line " | |
+ lineNumber + " of " | |
+ sourceID); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment