JS can call Android and get a value back!

This commit is contained in:
Bradlee Speice
2014-09-01 14:32:13 -04:00
parent e20e42b7bd
commit ae43667f2f
4 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@ -125,6 +126,15 @@ public class BookFragment extends BaseFragment {
}
});
// We can receive and return only primitives and Strings. Still means we can use JSON :)
mainContent.addJavascriptInterface(new Object() {
@JavascriptInterface
@SuppressWarnings("unused")
public String testReturn(String echo) {
return echo;
}
}, "Android");
// TODO: Remove remote debugging when ready - or should this be removed?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);