Search in sources :

Example 21 with JavascriptInterface

use of android.webkit.JavascriptInterface in project ForPDA by RadiationX.

the class ThemeFragmentWeb method callbackUpdateHistoryHtml.

@JavascriptInterface
public void callbackUpdateHistoryHtml(String value) {
    ThemePage themePage = history.get(history.size() - 1);
    Log.d(LOG_TAG, "updateHistoryLastHtml " + themePage + " : " + currentPage);
    themePage.setScrollY(webView.getScrollY());
    themePage.setHtml(value);
}
Also used : ThemePage(forpdateam.ru.forpda.api.theme.models.ThemePage) JavascriptInterface(android.webkit.JavascriptInterface)

Example 22 with JavascriptInterface

use of android.webkit.JavascriptInterface in project fitpay-android-sdk by fitpay.

the class WebViewCommunicatorImpl method dispatchMessage.

@Override
@JavascriptInterface
public void dispatchMessage(String message) throws JSONException {
    if (message == null) {
        FPLog.w(WV_DATA, "\\Received\\: invalid message");
        throw new IllegalArgumentException("invalid message");
    }
    JSONObject obj = new JSONObject(message);
    String callBackId = obj.getString("callBackId");
    if (callBackId == null) {
        FPLog.w(WV_DATA, "\\Received\\: callBackId is missing in the message");
        throw new IllegalArgumentException("callBackId is missing in the message");
    }
    String type = obj.getString("type");
    if (type == null) {
        FPLog.w(WV_DATA, "\\Received\\: type is missing in the message");
        throw new IllegalArgumentException("type is missing in the message");
    }
    FPLog.i(WV_DATA, String.format(Locale.getDefault(), "\\Received\\: callbackId:%s type:%s", callBackId, type));
    String dataStr = obj.has("data") ? obj.getString("data") : null;
    RxBus.getInstance().post(new RtmMessage(callBackId, dataStr, type));
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) JSONObject(org.json.JSONObject) JavascriptInterface(android.webkit.JavascriptInterface)

Example 23 with JavascriptInterface

use of android.webkit.JavascriptInterface in project summer-android by cn-cerc.

the class JavaScriptProxy method list.

// 列出所有可用的服务
@JavascriptInterface
public String list() {
    Map<String, String> items = new LinkedHashMap<>();
    JSONObject json = new JSONObject();
    try {
        for (Class clazz : services.keySet()) {
            String[] args = clazz.getName().split("\\.");
            String temp = args[args.length - 1];
            json.put(temp, services.get(clazz));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return json.toString();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) LinkedHashMap(java.util.LinkedHashMap) JavascriptInterface(android.webkit.JavascriptInterface)

Example 24 with JavascriptInterface

use of android.webkit.JavascriptInterface in project summer-android by cn-cerc.

the class JavaScriptProxy method send.

// 调用指定的服务,须立即返回
@JavascriptInterface
public String send(String classCode, String dataIn) {
    String function = null;
    Class clazz = getClazz(classCode);
    JavaScriptResult json = new JavaScriptResult();
    JSONObject request = null;
    try {
        request = new JSONObject(dataIn);
        if (request.has("_callback_")) {
            function = request.getString("_callback_");
        }
        if (clazz != null) {
            Object object = clazz.newInstance();
            if (object instanceof JavaScriptService) {
                JavaScriptService object1 = (JavaScriptService) object;
                json.setData(object1.execute(this.owner, request));
                json.setResult(true);
                return json.toString();
            } else {
                json.setMessage("not support JavascriptInterface");
            }
        } else {
            json.setMessage("当前版本不支持: " + classCode);
        }
    } catch (InstantiationException e) {
        json.setMessage("InstantiationException");
    } catch (IllegalAccessException e) {
        json.setMessage("IllegalAccessException");
    } catch (Exception e) {
        json.setMessage(e.getMessage());
    }
    if (function != null && !"".equals(function)) {
        MyApp.getInstance().executiveJS(function, json.toString());
    }
    return json.toString();
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JavascriptInterface(android.webkit.JavascriptInterface)

Example 25 with JavascriptInterface

use of android.webkit.JavascriptInterface in project wigle-wifi-wardriving by wiglenet.

the class WiGLERegistrationInterface method registrationComplete.

/**
 * update the users authentication preferences from JS running in the page
 *
 * @param userName
 * @param userId
 * @param token
 */
@JavascriptInterface
public void registrationComplete(final String userName, final String userId, final String token) {
    MainActivity.info("Successful registration for " + userName + " auth ID: " + userId);
    final SharedPreferences prefs = MainActivity.getMainActivity().getSharedPreferences(ListFragment.SHARED_PREFS, 0);
    final SharedPreferences.Editor editor = prefs.edit();
    editor.putString(ListFragment.PREF_USERNAME, userName);
    editor.putString(ListFragment.PREF_AUTHNAME, userId);
    editor.putBoolean(ListFragment.PREF_BE_ANONYMOUS, false);
    editor.apply();
    TokenAccess.setApiToken(prefs, token);
    activity.finish();
}
Also used : SharedPreferences(android.content.SharedPreferences) JavascriptInterface(android.webkit.JavascriptInterface)

Aggregations

JavascriptInterface (android.webkit.JavascriptInterface)32 JSONObject (org.json.JSONObject)9 JSONException (org.json.JSONException)7 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 WebViewClient (android.webkit.WebViewClient)4 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 Method (java.lang.reflect.Method)4 File (java.io.File)3 SharedPreferences (android.content.SharedPreferences)2 IBaseForumPost (forpdateam.ru.forpda.api.IBaseForumPost)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SslError (android.net.http.SslError)1 Bundle (android.os.Bundle)1 AlertDialog (android.support.v7.app.AlertDialog)1 JsPromptResult (android.webkit.JsPromptResult)1