mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 15:38:35 -05:00
JS can call Android and get a value back!
This commit is contained in:
parent
e20e42b7bd
commit
ae43667f2f
@ -67,6 +67,7 @@ dependencies {
|
||||
compile 'com.netflix.rxjava:rxjava-android:+'
|
||||
compile 'com.android.support:appcompat-v7:20.+'
|
||||
compile 'org.apache.commons:commons-lang3:+'
|
||||
compile 'com.google.code.gson:gson:+'
|
||||
|
||||
androidTestCompile 'com.jayway.awaitility:awaitility:+'
|
||||
androidTestCompile 'org.mockito:mockito-core:+'
|
||||
|
2
app/src/main/assets/dist/book-bundle.js
vendored
2
app/src/main/assets/dist/book-bundle.js
vendored
@ -31,6 +31,8 @@ window.appendVerse = function(text) {
|
||||
return scope.$apply();
|
||||
};
|
||||
|
||||
console.log(Android.testReturn("Good morning."));
|
||||
|
||||
|
||||
/*
|
||||
Future reference: Get the controller scope like so:
|
||||
|
@ -23,6 +23,8 @@ window.appendVerse = (text) ->
|
||||
# Since we're calling outside of angular, we need to manually apply
|
||||
scope.$apply()
|
||||
|
||||
console.log Android.testReturn "Good morning."
|
||||
|
||||
###
|
||||
Future reference: Get the controller scope like so:
|
||||
angular.element($("<controller-element>")).scope().<function>
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user