Java Code Examples for android.webkit.ValueCallback#onReceiveValue()

The following examples show how to use android.webkit.ValueCallback#onReceiveValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AgentWebConfig.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
public static void removeSessionCookies(ValueCallback<Boolean> callback) {
    if (callback == null) {
        callback = getDefaultIgnoreCallback();
    }
    if (CookieManager.getInstance() == null) {
        callback.onReceiveValue(new Boolean(false));
        return;
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().removeSessionCookie();
        toSyncCookies();
        callback.onReceiveValue(new Boolean(true));
        return;
    }
    CookieManager.getInstance().removeSessionCookies(callback);
    toSyncCookies();
}
 
Example 2
Source File: DefaultChromeClient.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
private void createAndOpenCommonFileChooser(ValueCallback valueCallback, String mimeType) {
	Activity mActivity = this.mActivityWeakReference.get();
	if (mActivity == null || mActivity.isFinishing()) {
		valueCallback.onReceiveValue(new Object());
		return;
	}
	AgentWebUtils.showFileChooserCompat(mActivity,
			mWebView,
			null,
			null,
			this.mPermissionInterceptor,
			valueCallback,
			mimeType,
			null
	);
}
 
Example 3
Source File: X5WebViewEngine.java    From x5webview-cordova-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void evaluateJavascript(String js, ValueCallback<String> callback) {

    if(callback == null)
        webView.evaluateJavascript(js,null);

     final ValueCallback<String> proxyCallback = callback;
     com.tencent.smtt.sdk.ValueCallback mCallback = new com.tencent.smtt.sdk.ValueCallback() {
        @Override
        public void onReceiveValue(Object o) {
            if(o instanceof String)
                proxyCallback.onReceiveValue((String) o);
        }
    };
    webView.evaluateJavascript(js,mCallback);
}
 
Example 4
Source File: CBrowserMainFrame7.java    From appcan-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
{
    ValueCallback<Uri[]> uploadMessage = ((EBrowserActivity) mContext).getUploadMessage();
    if (uploadMessage != null) {
        uploadMessage.onReceiveValue(null);
        uploadMessage = null;
    }

    uploadMessage = filePathCallback;
    ((EBrowserActivity)mContext).setUploadMessage(uploadMessage);
    Intent intent = fileChooserParams.createIntent();
    try
    {
        ((EBrowserActivity)mContext).startActivityForResult(intent, REQUEST_SELECT_FILE);
    } catch (ActivityNotFoundException e)
    {
        uploadMessage = null;
        Toast.makeText(mContext, "Cannot Open File Chooser", Toast.LENGTH_LONG).show();
        return false;
    }
    return true;
}
 
Example 5
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
	Boolean returnValue = false;

	if (shouldCallSuper("onShowFileChooser")) {
		returnValue = super.onShowFileChooser(webView, filePathCallback, fileChooserParams);
	}
	if (shouldSendEvent("onShowFileChooser")) {
		WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.WEBPLAYER, WebPlayerEvent.SHOW_FILE_CHOOSER, viewId);
	}
	if (hasReturnValue("onShowFileChooser")) {
		returnValue = getReturnValue("onShowFileChooser", java.lang.Boolean.class, true);
		if (returnValue) {
			filePathCallback.onReceiveValue(null);
		}
	}

	return returnValue;
}
 
Example 6
Source File: BrowserActivity.java    From Ninja with Apache License 2.0 6 votes vote down vote up
@Override
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
    // Because Activity launchMode is singleInstance,
    // so we can not get result from onActivityResult when Android 4.X,
    // what a pity
    //
    // this.uploadMsg = uploadMsg;
    // Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    // intent.addCategory(Intent.CATEGORY_OPENABLE);
    // intent.setType("*/*");
    // startActivityForResult(Intent.createChooser(intent, getString(R.string.main_file_chooser)), IntentUnit.REQUEST_FILE_16);
    uploadMsg.onReceiveValue(null);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);

    FrameLayout layout = (FrameLayout) getLayoutInflater().inflate(R.layout.dialog_desc, null, false);
    TextView textView = (TextView) layout.findViewById(R.id.dialog_desc);
    textView.setText(R.string.dialog_content_upload);

    builder.setView(layout);
    builder.create().show();
}
 
Example 7
Source File: XWalkCordovaResourceClient.java    From cordova-crosswalk-engine with Apache License 2.0 6 votes vote down vote up
/**
* Notify the host application that an SSL error occurred while loading a
* resource. The host application must call either callback.onReceiveValue(true)
* or callback.onReceiveValue(false). Note that the decision may be
* retained for use in response to future SSL errors. The default behavior
* is to pop up a dialog.
*/
@Override
public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) {
    final String packageName = parentEngine.cordova.getActivity().getPackageName();
    final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            callback.onReceiveValue(true);
        } else {
            // debug = false
            callback.onReceiveValue(false);
        }
    } catch (PackageManager.NameNotFoundException e) {
        // When it doubt, lock it out!
        callback.onReceiveValue(false);
    }
}
 
Example 8
Source File: CordovaActivity.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
@Override
    /**
     * Called when an activity you launched exits, giving you the requestCode you started it with,
     * the resultCode it returned, and any additional data from it.
     *
     * @param requestCode       The request code originally supplied to startActivityForResult(),
     *                          allowing you to identify who this result came from.
     * @param resultCode        The integer result code returned by the child activity through its setResult().
     * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
     */
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        LOG.d(TAG, "Incoming Result");
        super.onActivityResult(requestCode, resultCode, intent);
        Log.d(TAG, "Request code = " + requestCode);
        if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
        	ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
            Log.d(TAG, "did we get here?");
            if (null == mUploadMessage)
                return;
            Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
            Log.d(TAG, "result = " + result);
//            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
//            Log.d(TAG, "result = " + filepath);
            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;
        }
        CordovaPlugin callback = this.activityResultCallback;
        if(callback == null && initCallbackClass != null) {
            // The application was restarted, but had defined an initial callback
            // before being shut down.
            this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
            callback = this.activityResultCallback;
        }
        if(callback != null) {
            LOG.d(TAG, "We have a callback to send this result to");
            callback.onActivityResult(requestCode, resultCode, intent);
        }
    }
 
Example 9
Source File: CordovaActivity.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
@Override
    /**
     * Called when an activity you launched exits, giving you the requestCode you started it with,
     * the resultCode it returned, and any additional data from it.
     *
     * @param requestCode       The request code originally supplied to startActivityForResult(),
     *                          allowing you to identify who this result came from.
     * @param resultCode        The integer result code returned by the child activity through its setResult().
     * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
     */
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        LOG.d(TAG, "Incoming Result");
        super.onActivityResult(requestCode, resultCode, intent);
        Log.d(TAG, "Request code = " + requestCode);
        if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
        	ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
            Log.d(TAG, "did we get here?");
            if (null == mUploadMessage)
                return;
            Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
            Log.d(TAG, "result = " + result);
//            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
//            Log.d(TAG, "result = " + filepath);
            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;
        }
        CordovaPlugin callback = this.activityResultCallback;
        if(callback == null && initCallbackClass != null) {
            // The application was restarted, but had defined an initial callback
            // before being shut down.
            this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
            callback = this.activityResultCallback;
        }
        if(callback != null) {
            LOG.d(TAG, "We have a callback to send this result to");
            callback.onActivityResult(requestCode, resultCode, intent);
        }
    }
 
Example 10
Source File: CBrowserMainFrame.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public WebViewSdkCompat.ValueCallback<Uri> getCompatCallback(final ValueCallback<Uri> uploadMsg){
    return new WebViewSdkCompat.ValueCallback<Uri>() {
        @Override
        public void onReceiveValue(Uri uri) {
            uploadMsg.onReceiveValue(uri);
        }
    };
}
 
Example 11
Source File: CBrowserMainFrame.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public WebViewSdkCompat.ValueCallback<Uri> getCompatCallback(final ValueCallback<Uri> uploadMsg){
    return new WebViewSdkCompat.ValueCallback<Uri>() {
        @Override
        public void onReceiveValue(Uri uri) {
            uploadMsg.onReceiveValue(uri);
        }
    };
}
 
Example 12
Source File: CordovaActivity.java    From reader with MIT License 5 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode you started it with,
 * the resultCode it returned, and any additional data from it.
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    LOG.d(TAG, "Incoming Result");
    super.onActivityResult(requestCode, resultCode, intent);
    Log.d(TAG, "Request code = " + requestCode);
    if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
    	ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
        Log.d(TAG, "did we get here?");
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
        Log.d(TAG, "result = " + result);
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;
    }
    CordovaPlugin callback = this.activityResultCallback;
    if(callback == null && initCallbackClass != null) {
        // The application was restarted, but had defined an initial callback
        // before being shut down.
        this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
        callback = this.activityResultCallback;
    }
    if(callback != null) {
        LOG.d(TAG, "We have a callback to send this result to");
        callback.onActivityResult(requestCode, resultCode, intent);
    }
}
 
Example 13
Source File: CordovaActivity.java    From reader with MIT License 5 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode you started it with,
 * the resultCode it returned, and any additional data from it.
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    LOG.d(TAG, "Incoming Result");
    super.onActivityResult(requestCode, resultCode, intent);
    Log.d(TAG, "Request code = " + requestCode);
    if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
    	ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
        Log.d(TAG, "did we get here?");
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
        Log.d(TAG, "result = " + result);
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;
    }
    CordovaPlugin callback = this.activityResultCallback;
    if(callback == null && initCallbackClass != null) {
        // The application was restarted, but had defined an initial callback
        // before being shut down.
        this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
        callback = this.activityResultCallback;
    }
    if(callback != null) {
        LOG.d(TAG, "We have a callback to send this result to");
        callback.onActivityResult(requestCode, resultCode, intent);
    }
}
 
Example 14
Source File: CordovaActivity.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
/**
 * Called when an activity you launched exits, giving you the requestCode you started it with,
 * the resultCode it returned, and any additional data from it.
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    LOG.d(TAG, "Incoming Result");
    super.onActivityResult(requestCode, resultCode, intent);
    Log.d(TAG, "Request code = " + requestCode);
    if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
    	ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
        Log.d(TAG, "did we get here?");
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
        Log.d(TAG, "result = " + result);
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;
    }
    CordovaPlugin callback = this.activityResultCallback;
    if(callback == null && initCallbackClass != null) {
        // The application was restarted, but had defined an initial callback
        // before being shut down.
        this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
        callback = this.activityResultCallback;
    }
    if(callback != null) {
        LOG.d(TAG, "We have a callback to send this result to");
        callback.onActivityResult(requestCode, resultCode, intent);
    }
}
 
Example 15
Source File: EditAreaView.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
@JavascriptInterface
public void returnValue(long id, String value) {
    ValueCallback<String> callback = callbackMap.get(id);
    if (callback != null) {
        callback.onReceiveValue(value);
        callbackMap.remove(id);
    }
}
 
Example 16
Source File: WebViewActivity.java    From mattermost-android-classic with Apache License 2.0 5 votes vote down vote up
public boolean onShowFileChooser(
        WebView webView, ValueCallback<Uri[]> filePathCallback,
        FileChooserParams fileChooserParams) {

    String acceptTypes[] = fileChooserParams.getAcceptTypes();

    String acceptType = "";
    for (int i = 0; i < acceptTypes.length; ++i) {
        if (acceptTypes[i] != null && acceptTypes[i].length() != 0)
            acceptType += acceptTypes[i] + ";";
    }
    if (acceptType.length() == 0)
        acceptType = "*/*";

    final ValueCallback<Uri[]> finalFilePathCallback = filePathCallback;

    ValueCallback<Uri> vc = new ValueCallback<Uri>() {

        @Override
        public void onReceiveValue(Uri value) {

            Uri[] result;
            if (value != null)
                result = new Uri[]{value};
            else
                result = null;

            finalFilePathCallback.onReceiveValue(result);

        }
    };

    openFileChooser(vc, acceptType, "filesystem");

    return true;
}
 
Example 17
Source File: AgentWebConfig.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
public static void removeAllCookies(@Nullable ValueCallback<Boolean> callback) {
    if (callback == null) {
        callback = getDefaultIgnoreCallback();
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().removeAllCookie();
        toSyncCookies();
        callback.onReceiveValue(!CookieManager.getInstance().hasCookies());
        return;
    }
    CookieManager.getInstance().removeAllCookies(callback);
    toSyncCookies();
}
 
Example 18
Source File: CornUIClient.java    From Cornowser with MIT License 4 votes vote down vote up
@Override
public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, ValueCallback<XWalkView> callback) {
    CornBrowser.getTabSwitcher().addTab(new Tab());
    callback.onReceiveValue(CornBrowser.getTabSwitcher().getCurrentTab().getWebView());
    return true;
}
 
Example 19
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 4 votes vote down vote up
static boolean showFileChooserCompat(Activity activity,
	                                     WebView webView,
	                                     ValueCallback<Uri[]> valueCallbacks,
	                                     WebChromeClient.FileChooserParams fileChooserParams,
	                                     PermissionInterceptor permissionInterceptor,
	                                     ValueCallback valueCallback,
	                                     String mimeType,
	                                     Handler.Callback jsChannelCallback
	) {
		try {
			Class<?> clz = Class.forName("com.just.agentweb.filechooser.FileChooser");
			Object mFileChooser$Builder = clz.getDeclaredMethod("newBuilder",
					Activity.class, WebView.class)
					.invoke(null, activity, webView);
			clz = mFileChooser$Builder.getClass();
			Method mMethod = null;
			if (valueCallbacks != null) {
				mMethod = clz.getDeclaredMethod("setUriValueCallbacks", ValueCallback.class);
				mMethod.setAccessible(true);
				mMethod.invoke(mFileChooser$Builder, valueCallbacks);
			}
			if (fileChooserParams != null) {
				mMethod = clz.getDeclaredMethod("setFileChooserParams", WebChromeClient.FileChooserParams.class);
				mMethod.setAccessible(true);
				mMethod.invoke(mFileChooser$Builder, fileChooserParams);
			}
			if (valueCallback != null) {
				mMethod = clz.getDeclaredMethod("setUriValueCallback", ValueCallback.class);
				mMethod.setAccessible(true);
				mMethod.invoke(mFileChooser$Builder, valueCallback);
			}
			if (!TextUtils.isEmpty(mimeType)) {
//                LogUtils.i(TAG, Arrays.toString(clz.getDeclaredMethods()));
				mMethod = clz.getDeclaredMethod("setAcceptType", String.class);
				mMethod.setAccessible(true);
				mMethod.invoke(mFileChooser$Builder, mimeType);
			}
			if (jsChannelCallback != null) {
				mMethod = clz.getDeclaredMethod("setJsChannelCallback", Handler.Callback.class);
				mMethod.setAccessible(true);
				mMethod.invoke(mFileChooser$Builder, jsChannelCallback);
			}
			mMethod = clz.getDeclaredMethod("setPermissionInterceptor", PermissionInterceptor.class);
			mMethod.setAccessible(true);
			mMethod.invoke(mFileChooser$Builder, permissionInterceptor);
			mMethod = clz.getDeclaredMethod("build");
			mMethod.setAccessible(true);
			Object mFileChooser = mMethod.invoke(mFileChooser$Builder);
			mMethod = mFileChooser.getClass().getDeclaredMethod("openFileChooser");
			mMethod.setAccessible(true);
			mMethod.invoke(mFileChooser);
		} catch (Throwable throwable) {
			if (LogUtils.isDebug()) {
				throwable.printStackTrace();
			}
			if (throwable instanceof ClassNotFoundException) {
				LogUtils.e(TAG, "Please check whether compile'com.just.agentweb:filechooser:x.x.x' dependency was added.");
			}
			if (valueCallbacks != null) {
				LogUtils.i(TAG, "onReceiveValue empty");
				return false;
			}
			if (valueCallback != null) {
				valueCallback.onReceiveValue(null);
			}
		}
		return true;
	}
 
Example 20
Source File: MainActivity.java    From VBrowser-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) {
    callback.onReceiveValue(true);
}