// Enable pinch to zoom without the zoom buttons
webView.getSettings().setBuiltInZoomControls(true);
// Enable pinch to zoom without the zoom buttons
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
// Hide the zoom controls for HONEYCOMB+
webView.getSettings().setDisplayZoomControls(false);
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH)
webView.getSettings().setTextZoom(100);
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onCloseWindow(WebView w) {
super.onCloseWindow(w);
finish();
}
// For Android Version < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
//System.out.println("WebViewActivity OS Version : " + Build.VERSION.SDK_INT + "\t openFC(VCU), n=1");
mUploadMessage = uploadMsg;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(TYPE_IMAGE);
startActivityForResult(intent, INPUT_FILE_REQUEST_CODE);
}
// For 3.0 <= Android Version < 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
//System.out.println("WebViewActivity 3<A<4.1, OS Version : " + Build.VERSION.SDK_INT + "\t openFC(VCU,aT), n=2");
openFileChooser(uploadMsg, acceptType, "");
}
// For 4.1 <= Android Version < 5.0
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
Log.d(getClass().getName(), "openFileChooser : "+acceptType+"/"+capture);
mUploadMessage = uploadFile;
imageChooser();
}
// For Android Version 5.0+
// Ref: https://github.com/GoogleChrome/chromium-webview-samples/blob/master/input-file-example/app/src/main/java/inputfilesample/android/chrome/google/com/inputfilesample/MainFragment.java
public boolean onShowFileChooser(WebView webView,
ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
System.out.println("WebViewActivity A>5, OS Version : " + Build.VERSION.SDK_INT + "\t onSFC(WV,VCUB,FCP), n=3");
if (mFilePathCallback != null) {
mFilePathCallback.onReceiveValue(null);
}
mFilePathCallback = filePathCallback;
imageChooser();
return true;
}
private void imageChooser() {
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(getClass().getName(), "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(TYPE_IMAGE);
Intent[] intentArray;
if(takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else {
intentArray = new Intent[0];
}
private Uri getResultUri(Intent data) {
Uri result = null;
if(data == null || TextUtils.isEmpty(data.getDataString())) {
// If there is not data, then we may have taken a photo
if(mCameraPhotoPath != null) {
result = Uri.parse(mCameraPhotoPath);
}
} else {
String filePath = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
filePath = data.getDataString();
} else {
filePath = "file:" + RealPathUtil.getRealPath(this, data.getData());
}
result = Uri.parse(filePath);
}