Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. public class ChromeClient extends WebChromeClient {
  2. // For Android 5.0
  3. public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
  4. // Double check that we don't have any existing callbacks
  5. if (mFilePathCallback != null) {
  6. mFilePathCallback.onReceiveValue(null);
  7. }
  8. mFilePathCallback = filePath;
  9. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  10. if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
  11. // Create the File where the photo should go
  12. File photoFile = null;
  13. try {
  14. photoFile = createImageFile();
  15. takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
  16. } catch (IOException ex) {
  17. // Error occurred while creating the File
  18. Log.e("asd", "Unable to create Image File", ex);
  19. }
  20. // Continue only if the File was successfully created
  21. if (photoFile != null) {
  22. mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
  23. takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
  24. Uri.fromFile(photoFile));
  25. } else {
  26. takePictureIntent = null;
  27. }
  28. }
  29. Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
  30. contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
  31. contentSelectionIntent.setType("image/*");
  32. Intent[] intentArray;
  33. if (takePictureIntent != null) {
  34. intentArray = new Intent[]{takePictureIntent};
  35. } else {
  36. intentArray = new Intent[0];
  37. }
  38. Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
  39. chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
  40. chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
  41. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
  42. startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
  43. return true;
  44. }
  45. }
  46.  
  47. public class Client extends WebViewClient {
  48. ProgressDialog progressDialog;
  49. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  50. // If url contains mailto link then open Mail Intent
  51. if (url.contains("mailto:")) {
  52. // Could be cleverer and use a regex
  53. //Open links in new browser
  54. view.getContext().startActivity(
  55. new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
  56. // Here we can open new activity
  57. return true;
  58. }else {
  59. // Stay within this webview and load url
  60. view.loadUrl(url);
  61. return true;
  62. }
  63. }
  64. //Show loader on url load
  65. public void onPageStarted(WebView view, String url, Bitmap favicon) {
  66. // Then show progress Dialog
  67. // in standard case YourActivity.this
  68. if (progressDialog == null) {
  69. progressDialog = new ProgressDialog(MainActivity.this);
  70. progressDialog.setMessage("Caricamento...");
  71. progressDialog.show();
  72. }
  73. }
  74. // Called when all page resources loaded
  75. public void onPageFinished(WebView view, String url) {
  76. try {
  77. // Close progressDialog
  78. if (progressDialog.isShowing()) {
  79. progressDialog.dismiss();
  80. progressDialog = null;
  81. }
  82. } catch (Exception exception) {
  83. exception.printStackTrace();
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement