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();
}
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();
});
}
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());
});
}
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);
}
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);
}
});
}
Aggregations