android 中 H5页面无法调用相册之类 怎么办

android 中 H5页面无法调用相册之类 怎么办,第1张

概述1wvWebview.setWebChromeClient(newWebChromeClient(){2@Override3publicvoidonProgressChanged(WebViewview,intnewProgress){4if(newProgress==100){5bar.setVisibility(View.I
 1     wvWebvIEw.setWebChromeClIEnt(new WebChromeClIEnt() { 2             @OverrIDe 3             public voID onProgressChanged(WebVIEw vIEw, int newProgress) { 4                 if (newProgress == 100) { 5                     bar.setVisibility(VIEw.INVISIBLE); 6                     // line.setVisibility(VIEw.VISIBLE); 7                 } else { 8                     if (VIEw.INVISIBLE == bar.getVisibility()) { 9                         bar.setVisibility(VIEw.VISIBLE);10                     }11                     bar.setVisibility(VIEw.INVISIBLE);12                     bar.setProgress(newProgress);13                     bar.setVisibility(VIEw.VISIBLE);14                 }15                 super.onProgressChanged(vIEw, newProgress);16             }17 18             /**19              * 8(AndroID 2.2) <= API <= 10(AndroID 2.3)回调此方法20              */21             private voID openfileChooser(androID.webkit.ValueCallback<Uri> uploadMsg) {22                 Log.e("WangJ", "运行方法 openfileChooser-1");23                 // (2)该方法回调时说明版本API < 21,此时将结果赋值给 mUploadCallbackBelow,使之 != null24                 mUploadCallbackBelow = uploadMsg;25                 takePhoto();26             }27 28             /**29              * 11(AndroID 3.0) <= API <= 15(AndroID 4.0.3)回调此方法30              */31             public voID openfileChooser(androID.webkit.ValueCallback<Uri> uploadMsg, String acceptType) {32                 Log.e("WangJ", "运行方法 openfileChooser-2 (acceptType: " + acceptType + ")");33                 // 这里我们就不区分input的参数了,直接用拍照34                 openfileChooser(uploadMsg);35             }36 37             /**38              * 16(AndroID 4.1.2) <= API <= 20(AndroID 4.4W.2)回调此方法39              */40             public voID openfileChooser(androID.webkit.ValueCallback<Uri> uploadMsg, String acceptType, String capture) {41                 Log.e("WangJ", "运行方法 openfileChooser-3 (acceptType: " + acceptType + "; capture: " + capture + ")");42                 // 这里我们就不区分input的参数了,直接用拍照43                 openfileChooser(uploadMsg);44             }45 46             /**47              * API >= 21(AndroID 5.0.1)回调此方法48              */49             @OverrIDe50             public boolean onShowfileChooser(WebVIEw webVIEw, ValueCallback<Uri[]> valueCallback, fileChooserParams fileChooserParams) {51                 Log.e("WangJ", "运行方法 onShowfileChooser");52                 // (1)该方法回调时说明版本API >= 21,此时将结果赋值给 mUploadCallbackAboveL,使之 != null53                 mUploadCallbackAboveL = valueCallback;54                 takePhoto();55                 return true;56             }57 58         });

 

 1  /** 2      * 调用相机 3      */ 4     private voID takePhoto() { 5         // 指定拍照存储位置的方式调起相机 6         String filePath = Environment.getExternalStorageDirectory() + file.separator 7                 + Environment.DIRECTORY_PICTURES + file.separator; 8         String filename = "img_" + DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg"; 9         imageUri = Uri.fromfile(new file(filePath + filename));10 11         //        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);12         //        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);13         //        startActivityForResult(intent, REQUEST_CODE);14 15 16         // 选择图片(不包括相机拍照),则不用成功后发刷新图库的广播17         //        Intent i = new Intent(Intent.ACTION_GET_CONTENT);18         //        i.addcategory(Intent.category_OPENABLE);19         //        i.setType("image/*");20         //        startActivityForResult(Intent.createChooser(i, "Image Chooser"), REQUEST_CODE);21 22         Intent captureIntent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE);23         captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);24 25         Intent Photo = new Intent(Intent.ACTION_PICK,26                 androID.provIDer.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);27 28         Intent chooserIntent = Intent.createChooser(Photo, "Image Chooser");29         chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[]{captureIntent});30 31         startActivityForResult(chooserIntent, 99);32     }

 

 1  /** 2      * AndroID API < 21(AndroID 5.0)版本的回调处理 3      * @param resultCode 4      *         选取文件或拍照的返回码 5      * @param data 6      *         选取文件或拍照的返回结果 7      */ 8     private voID chooseBelow(int resultCode, Intent data) { 9         Log.e("WangJ", "返回调用方法--chooseBelow");10 11         if (RESulT_OK == resultCode) {12             updatePhotos();13 14             if (data != null) {15                 // 这里是针对文件路径处理16                 Uri uri = data.getData();17                 if (uri != null) {18                     Log.e("WangJ", "系统返回URI:" + uri.toString());19                     mUploadCallbackBelow.onReceiveValue(uri);20                 } else {21                     mUploadCallbackBelow.onReceiveValue(null);22                 }23             } else {24                 // 以指定图像存储路径的方式调起相机,成功后返回data为空25                 Log.e("WangJ", "自定义结果:" + imageUri.toString());26                 mUploadCallbackBelow.onReceiveValue(imageUri);27             }28         } else {29             mUploadCallbackBelow.onReceiveValue(null);30         }31         mUploadCallbackBelow = null;32     }33 34     /**35      * AndroID API >= 21(AndroID 5.0) 版本的回调处理36      * @param resultCode37      *         选取文件或拍照的返回码38      * @param data39      *         选取文件或拍照的返回结果40      */41     private voID chooseAbove(int resultCode, Intent data) {42         Log.e("WangJ", "返回调用方法--chooseAbove");43 44         if (RESulT_OK == resultCode) {45             updatePhotos();46 47             if (data != null) {48                 // 这里是针对从文件中选图片的处理49                 Uri[] results;50                 Uri urIData = data.getData();51                 if (urIData != null) {52                     results = new Uri[]{urIData};53                     for (Uri uri : results) {54                         Log.e("WangJ", "系统返回URI:" + uri.toString());55                     }56                     mUploadCallbackAboveL.onReceiveValue(results);57                 } else {58                     mUploadCallbackAboveL.onReceiveValue(null);59                 }60             } else {61                 Log.e("WangJ", "自定义结果:" + imageUri.toString());62                 mUploadCallbackAboveL.onReceiveValue(new Uri[]{imageUri});63             }64         } else {65             mUploadCallbackAboveL.onReceiveValue(null);66         }67         mUploadCallbackAboveL = null;68     }69 70     private androID.webkit.ValueCallback<Uri[]> mUploadCallbackAboveL;71     private androID.webkit.ValueCallback<Uri>   mUploadCallbackBelow;72 73     private voID updatePhotos() {74         // 该广播即使多发(即选取照片成功时也发送)也没有关系,只是唤醒系统刷新媒体文件75         Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_file);76         intent.setData(imageUri);77         sendbroadcast(intent);78     }

这样配置 即可  稳稳当当 过

总结

以上是内存溢出为你收集整理的android 中 H5页面无法调用相册之类 怎么办全部内容,希望文章能够帮你解决android 中 H5页面无法调用相册之类 怎么办所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1058644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存