import android.net.Uri; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebView; public class ReWebChomeClient extends WebChromeClient { private OpenFileChooserCallBack mOpenFileChooserCallBack; public ReWebChomeClient(OpenFileChooserCallBack openFileChooserCallBack) { mOpenFileChooserCallBack = openFileChooserCallBack; } //For Android 3.0+ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { MyLog.d("ttt","webview调用相册3.0+"); mOpenFileChooserCallBack.openFileChooserCallBack(uploadMsg, acceptType); } // For Android < 3.0 public void openFileChooser(ValueCallback<Uri> uploadMsg) { MyLog.d("ttt","webview调用相册3.0-"); openFileChooser(uploadMsg, ""); } // For Android > 4.1.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { MyLog.d("ttt","webview调用相册4.1.1+"); openFileChooser(uploadMsg, acceptType); } public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> uploadMsg, WebChromeClient.FileChooserParams fileChooserParams) { // openFileChooserImplForAndroid5(uploadMsg); MyLog.d("ttt","webview调用相册5.0+"); mOpenFileChooserCallBack.onShowFileChooserCallBack(uploadMsg); return true; } public interface OpenFileChooserCallBack { void openFileChooserCallBack(ValueCallback<Uri> uploadMsg, String acceptType); void onShowFileChooserCallBack(ValueCallback<Uri[]> uploadMsg); }}
public void showOptions() { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setOnCancelListener(new ReOnCancelListener()); alertDialog.setTitle(R.string.options); alertDialog.setItems(R.array.options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { mSourceIntent = ImageUtil.choosePicture(); startActivityForResult(mSourceIntent, REQUEST_CODE_PICK_IMAGE); } else { mSourceIntent = ImageUtil.takeBigPicture(); startActivityForResult(mSourceIntent, REQUEST_CODE_IMAGE_CAPTURE); } } } ); alertDialog.show(); }public static Intent choosePicture() { Intent intent = new Intent( Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); return Intent.createChooser(intent, null); } public static Intent takeBigPicture() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, newPictureUri(getNewPhotoPath())); return intent; }
Webview调用本地相册
最新推荐文章于 2024-02-22 10:04:44 发布