Java Code Examples for android.webkit.WebChromeClient#FileChooserParams

The following examples show how to use android.webkit.WebChromeClient#FileChooserParams . 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: MainFragment.java    From traccar-manager-android with Apache License 2.0 6 votes vote down vote up
public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    if (openFileCallback2 != null) {
        openFileCallback2.onReceiveValue(null);
        openFileCallback2 = null;
    }

    openFileCallback2 = filePathCallback;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Intent intent = fileChooserParams.createIntent();
        try {
            startActivityForResult(intent, REQUEST_FILE_CHOOSER);
        } catch (ActivityNotFoundException e) {
            openFileCallback2 = null;
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: BrowserActivity.java    From Ninja with Apache License 2.0 6 votes vote down vote up
@Override
public void showFileChooser(ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        this.filePathCallback = filePathCallback;

        try {
            Intent intent = fileChooserParams.createIntent();
            startActivityForResult(intent, IntentUnit.REQUEST_FILE_21);
        } catch (Exception e) {
            NinjaToast.show(this, R.string.toast_open_file_manager_failed);
        }
    }
}
 
Example 3
Source File: VideoEnabledWebChromeClient.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> uploadMsg, WebChromeClient.FileChooserParams fileChooserParams) {
    MainActivity.current().getStateListener().launch((resultCode, data)
                    -> uploadMsg.onReceiveValue(new Uri[]{data.getData()})
            , fileChooserParams.createIntent());
    return true;
}
 
Example 4
Source File: CustomWebViewModule.java    From react-native-webview-android-file-upload with MIT License 5 votes vote down vote up
private void startFileChooser(WebChromeClient.FileChooserParams fileChooserParams) {
    final String[] acceptTypes = getSafeAcceptedTypes(fileChooserParams);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final boolean allowMultiple = fileChooserParams.getMode() == WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE;

        Intent intent = fileChooserParams.createIntent();
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_MIME_TYPES, getAcceptedMimeType(acceptTypes));
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
        getCurrentActivity().startActivityForResult(intent, SELECT_FILE);
    }
}
 
Example 5
Source File: CustomWebViewModule.java    From react-native-webview-android-file-upload with MIT License 5 votes vote down vote up
private String[] getSafeAcceptedTypes(WebChromeClient.FileChooserParams params) {

        // the getAcceptTypes() is available only in api 21+
        // for lower level, we ignore it
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            return params.getAcceptTypes();
        }

        final String[] EMPTY = {};
        return EMPTY;
    }
 
Example 6
Source File: FileChooser.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    setFilePathCallbacks(filePathCallback);
    String[] acceptTypes = new String[0];
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        acceptTypes = fileChooserParams.getAcceptTypes();
    }
    dealOpenFileChooser(acceptTypes.length > 0 ? acceptTypes[0] : "");
}
 
Example 7
Source File: HolderService.java    From Ninja with Apache License 2.0 4 votes vote down vote up
@Override
public void showFileChooser(ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {}
 
Example 8
Source File: LightningChromeClient.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                                 WebChromeClient.FileChooserParams fileChooserParams) {
    mUIController.showFileChooser(filePathCallback);
    return true;
}
 
Example 9
Source File: MainActivity.java    From FaceSlim with GNU General Public License v2.0 4 votes vote down vote up
public boolean onShowFileChooser(
        WebView webView, ValueCallback<Uri[]> filePathCallback,
        WebChromeClient.FileChooserParams fileChooserParams) {

    /** Request permission for external storage access.
     *  If granted it's awesome and go on,
     *  otherwise just stop here and leave the method.
     */
    requestStoragePermission();
    if (!hasStoragePermission())
        return false;

    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

        // create the file where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(TAG, "Unable to create Image File", ex);
        }

        // continue only if the file was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("*/*");

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[]{takePictureIntent};
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.image_chooser));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

    startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

    return true;
}
 
Example 10
Source File: WebChromeClientListener.java    From JsBridge with MIT License 4 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    return false;
}
 
Example 11
Source File: MainActivity.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
public boolean onShowFileChooser(
        WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    requestStoragePermission();
    if (!hasStoragePermission())
        return false;

    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

        // create the file where the photo should go
        File photoFile;
        photoFile = createImageFile();
        takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);

        // continue only if the file was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("*/*");
    contentSelectionIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*", "*/*"});

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[]{takePictureIntent};
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose file");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
    startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

    return true;
}
 
Example 12
Source File: PrivateActivity.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
public boolean onShowFileChooser(
        WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    requestStoragePermission();
    if (!hasStoragePermission())
        return false;

    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {

        // create the file where the photo should go
        File photoFile;
        photoFile = createImageFile();
        takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);

        // continue only if the file was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("*/*");
    contentSelectionIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*", "*/*"});

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[]{takePictureIntent};
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose file");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
    startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

    return true;
}
 
Example 13
Source File: LightningChromeClient.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                                 WebChromeClient.FileChooserParams fileChooserParams) {
    mUIController.showFileChooser(filePathCallback);
    return true;
}
 
Example 14
Source File: MainActivity.java    From Android-File-Chooser with GNU General Public License v3.0 4 votes vote down vote up
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
    // Double check that we don't have any existing callbacks
    if (mUploadMessage != null) {
        mUploadMessage.onReceiveValue(null);
    }
    mUploadMessage = filePath;
    Log.e("FileCooserParams => ", filePath.toString());

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(TAG, "Unable to create Image File", ex);
        }

        // Continue only if the File was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    contentSelectionIntent.setType("image/*");

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[]{takePictureIntent};
    } else {
        intentArray = new Intent[2];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
    startActivityForResult(Intent.createChooser(chooserIntent, "Select images"), 1);

    return true;

}
 
Example 15
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 16
Source File: FileChooser.java    From AgentWeb with Apache License 2.0 4 votes vote down vote up
public Builder setFileChooserParams(WebChromeClient.FileChooserParams fileChooserParams) {
    mFileChooserParams = fileChooserParams;
    return this;
}
 
Example 17
Source File: MyWebChromeClient.java    From MaoWanAndoidClient with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> uploadMsg, WebChromeClient.FileChooserParams fileChooserParams) {
    openFileChooserImplForAndroid5(uploadMsg);
    return true;
}
 
Example 18
Source File: Main2Activity.java    From styT with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    uploadMessageAboveL = filePathCallback;
    openImageChooserActivity();
    return true;
}
 
Example 19
Source File: IFileChooser.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License votes vote down vote up
void showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams); 
Example 20
Source File: OnWebChromeClientListener.java    From JsBridge with MIT License votes vote down vote up
boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams);