Search in sources :

Example 6 with JavascriptInterface

use of android.webkit.JavascriptInterface in project BlogSource by TeachCourse.

the class ZXingJSWebViewActivity method finishMyself.

@JavascriptInterface
public void finishMyself() {
    setResult(RESULT_OK, new Intent(this, CaptureActivity.class));
    finish();
}
Also used : Intent(android.content.Intent) CaptureActivity(cn.teachcourse.scancode.CaptureActivity) JavascriptInterface(android.webkit.JavascriptInterface)

Example 7 with JavascriptInterface

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

the class ThemeFragmentWeb method anchorDialog.

@JavascriptInterface
public void anchorDialog(String postId, String name) {
    if (getContext() == null)
        return;
    runInUiThread(() -> {
        IBaseForumPost post = getPostById(Integer.parseInt(postId));
        String link = "https://4pda.ru/forum/index.php?act=findpost&pid=" + post.getId() + "&anchor=" + name;
        new AlertDialog.Builder(getContext()).setTitle(R.string.link_to_anchor).setMessage(link).setPositiveButton(R.string.copy, (dialog, which) -> {
            Utils.copyToClipBoard(link);
        }).setNegativeButton(R.string.cancel, null).show();
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) IBaseForumPost(forpdateam.ru.forpda.api.IBaseForumPost) JavascriptInterface(android.webkit.JavascriptInterface)

Example 8 with JavascriptInterface

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

the class ArticleContentFragment method sendPoll.

@JavascriptInterface
public void sendPoll(String id, String answer, String from) {
    if (getContext() == null)
        return;
    webView.runInUiThread(() -> {
        int pollId = Integer.parseInt(id);
        String[] answers = answer.split(",");
        int[] answersId = new int[answers.length];
        for (int i = 0; i < answers.length; i++) {
            answersId[i] = Integer.parseInt(answers[i]);
        }
        NewsDetailsFragment fragment = ((NewsDetailsFragment) getParentFragment());
        fragment.subscribe(RxApi.NewsList().sendPoll(from, pollId, answersId), page -> {
            article.setHtml(page.getHtml());
            loadHtml();
        }, new DetailsPage());
    });
}
Also used : DetailsPage(forpdateam.ru.forpda.api.news.models.DetailsPage) JavascriptInterface(android.webkit.JavascriptInterface)

Example 9 with JavascriptInterface

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

the class WebViewCommunicatorImpl method sendUserData.

@Override
@JavascriptInterface
public void sendUserData(String callbackId, String deviceId, String token, String userId) {
    this.deviceId = deviceId;
    FPLog.d(TAG, "sendUserData received data: deviceId: " + deviceId + ", token: " + token + ", userId: " + userId);
    OAuthToken oAuthToken = new OAuthToken.Builder().accessToken(token).build();
    ApiManager.getInstance().setAuthToken(oAuthToken);
    getUserAndDevice(deviceId, callbackId);
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) JavascriptInterface(android.webkit.JavascriptInterface)

Example 10 with JavascriptInterface

use of android.webkit.JavascriptInterface in project EasyBridge by easilycoder.

the class EasyBridge method enqueue.

/**
 * js invoke java async
 *
 * @param handlerName name
 * @param parameters  values from js
 * @param callbackId  the unique id to invoke js callback function
 */
@JavascriptInterface
public void enqueue(String handlerName, String currentPageUrl, final String parameters, String callbackId) {
    final Gson gson = new GsonBuilder().create();
    final ResultCallBack callBack = new ResultCallBack(callbackId) {

        @Override
        public void onResult(Object result) {
            dispatchResult(getCallbackId(), gson.toJson(CallBackMessage.generateSuccessMessage(result)));
        }
    };
    if (TextUtils.isEmpty(handlerName)) {
        callBack.onResult(CallBackMessage.generateErrorMessage(CallBackMessage.CODE_INVALID_HANDLER, "the handlerName is not invalid"));
        return;
    }
    final BridgeHandler handler = findTargetHandler(handlerName);
    if (handler == null) {
        callBack.onResult(CallBackMessage.generateErrorMessage(CallBackMessage.CODE_NO_HANDLER, "handler with name " + handlerName + " is not registered in Java code"));
        return;
    }
    // global security check
    if (!checkGlobalSecurity(currentPageUrl, parameters)) {
        callBack.onResult(CallBackMessage.generateErrorMessage(CODE_SECURITY_FORBIDDEN, "handler with name " + handlerName + " is not allowed to invoke in page:" + currentPageUrl + " by the global Security Checker"));
        return;
    }
    // handler security check
    if (handler.securityPolicyChecker() != null && !handler.securityPolicyChecker().check(currentPageUrl, parameters)) {
        callBack.onResult(CallBackMessage.generateErrorMessage(CODE_SECURITY_FORBIDDEN, "handler with name " + handlerName + " is not allowed to invoke in page:" + currentPageUrl));
        return;
    }
    // invoke the handler in main thread
    callBackHandler.post(new Runnable() {

        @Override
        public void run() {
            handler.onCall(parameters, callBack);
        }
    });
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) BridgeHandler(tech.easily.easybridge.lib.handler.BridgeHandler) Gson(com.google.gson.Gson) 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