Skip to content

Instantly share code, notes, and snippets.

@freakynit
Created December 5, 2014 10:34
Show Gist options
  • Save freakynit/d90137c0066c4d90382a to your computer and use it in GitHub Desktop.
Save freakynit/d90137c0066c4d90382a to your computer and use it in GitHub Desktop.
public class Temp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
// register class containing methods to be exposed to JavaScript
JSInterface = new JavaScriptInterface(this);
wv.addJavascriptInterface(JSInterface, "Android");
}
final class JavaScriptInterface {
Context mContext;
JavaScriptInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void showToast(String message) {
Toast.makeText(Temp.this, message, Toast.LENGTH_LONG).show();
}
@JavascriptInterface
public void showAndroidDialog(String message) {
// Some other code
}
@JavascriptInterface
public void moveToScreenTwo() {
Intent i = new Intent(Temp.this, NextActivity.class);
startActivity(i);
finish();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment