42896

Load Url Inside Javascript Interface Class

Question:

I am loading an url inside my interface, but they are not working;

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) public class MainActivity extends ActionBarActivity { WebView Browser; String website ="http://192.168.1.4/Soft/Bigcats/Ba/"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Browser=(WebView) findViewById(R.id.webView1) ; class MyJavaScriptInterface { @JavascriptInterface @SuppressWarnings("unused") public void Danyial(String Data) { Browser.loadUrl("http://enjoybaba.com"); } } Browser.addJavascriptInterface(new MyJavaScriptInterface(), "api"); Browser.loadUrl(website); Browser.setWebViewClient(new WebViewClient()); } }

Answer1:

you can accomplish this by adding these on your Javascript Interface Class

private Activity activity; public JavaScriptInterface(Activity act) { this.activity = act; }

Then Running loadUrl on a UI Thread

activity.runOnUiThread(new Runnable() { @Override public void run() { myWebView.loadUrl("http://google.com"); } });

Recommend

  • Why is this regex failing when adding anchors?
  • Daydream Non-VR Mode in Unity 5.4.2f-GVR13 [duplicate]
  • jquery ui datepicker error on beforeShowDay
  • Http request via one network interface
  • Communicate between asyncio protocol/servers
  • Does the program counter always have to change (upon a clock tick)?
  • Insert Pandas dataframe into Cassandra Table
  • Can you use multiple instances of Edge on a Selenium Grid Node?
  • Soap Envelope Header in Delphi 7 not including utf-8 encoding. How can I modify it?
  • Why does this empty dict break shared references?
  • HikariPool-1 - Unusual system clock change detected, soft-evicting connections from pool
  • Listview - list item selection and initial setting (custom made items)
  • Why does IE8 fail to resolve my JQuery selector for a checked radio option?
  • Unicorn and Rails eat up 2x MySQL connections
  • I have two activity.I want to Send the data from second activity to previous activity.First activity
  • Ruby and class variables in inherit class
  • What is the reason that Policy.getPolicy() is considered as it will retain a static reference to the
  • Unable to resolve Static method?
  • EditText is covered by Keyboard
  • Fully customized Python Help Usage
  • Swift Initialization Rule Confusion
  • How to upload specific List image using click on Upload button
  • Blackberry 6: how to detect a long click on track pad?
  • How to get listview position?
  • Laravel: Getting Session ID oddly truncates when using foreach
  • Bypass multiple inheritance in Java
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • how to avoid repetitive constructor in children
  • Recording logins for password protected directories
  • how to do an event when i swipe from fragment to the other
  • Update CALayer sublayers immediately
  • JFileChooser in front of fullscreen Swing application
  • Deleting and Updating values from a cusrsor adapter
  • Possible to stop flickering java tooltip in heavyweight mode?
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Turn off referential integrity in Derby? is it possible?
  • unknown Exception android
  • JaxB to read class hierarchy
  • failed to connect to specific WiFi in android programmatically