Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ChromeClient extends WebChromeClient {
- // For Android 5.0
- public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
- // Double check that we don't have any existing callbacks
- if (mFilePathCallback != null) {
- mFilePathCallback.onReceiveValue(null);
- }
- mFilePathCallback = filePath;
- 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("asd", "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("image/*");
- 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, "Image Chooser");
- chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
- startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
- return true;
- }
- }
- public class Client extends WebViewClient {
- ProgressDialog progressDialog;
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- // If url contains mailto link then open Mail Intent
- if (url.contains("mailto:")) {
- // Could be cleverer and use a regex
- //Open links in new browser
- view.getContext().startActivity(
- new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
- // Here we can open new activity
- return true;
- }else {
- // Stay within this webview and load url
- view.loadUrl(url);
- return true;
- }
- }
- //Show loader on url load
- public void onPageStarted(WebView view, String url, Bitmap favicon) {
- // Then show progress Dialog
- // in standard case YourActivity.this
- if (progressDialog == null) {
- progressDialog = new ProgressDialog(MainActivity.this);
- progressDialog.setMessage("Caricamento...");
- progressDialog.show();
- }
- }
- // Called when all page resources loaded
- public void onPageFinished(WebView view, String url) {
- try {
- // Close progressDialog
- if (progressDialog.isShowing()) {
- progressDialog.dismiss();
- progressDialog = null;
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement