Okay I've been working on this app for about a week now and I've just about got everything worked out. The only problem I have left is once I take the picture I need to resize it, but I can't seem to figure out what I'm doing wrong. When I tried to use the BitmapFactory to get the file everything looks like it's working fine until it gets to the Bitmap.createScaledBitmap portion of the resized function. If force closes when it gets to that line. Any help with this resize function would be greatly appreciated.
Code:
webView.setWebChromeClient(new WebChromeClient() {
//Capture image with camera on Android > 3.0
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
openFileChooser(uploadMsg);
}
//Capture image with camera on Android 3.0+
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
openFileChooser(uploadMsg);
}
//Capture image with camera on Android 4.1 to 4.3
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Mobile311_Citizen");
fullUrl = imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg";
file = new File(fullUrl);
Intent capture = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
capture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
MainActivity.this.startActivityForResult(capture, CAPTURE_RESULTCODE);
}
Code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
resize(fullUrl);
if(null == this.mUploadMessage){
this.mUploadMessage.onReceiveValue(null);
}else{
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, fullUrl);
this.mUploadMessage.onReceiveValue(this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values));
}
this.mUploadMessage = null;
}
}
Code:
private Bitmap resize(String path){
// create the options
BitmapFactory.Options opts = new BitmapFactory.Options();
//just decode the file
opts.inJustDecodeBounds = true;
Bitmap bp = BitmapFactory.decodeFile(path, opts);
//get the original size
int orignalHeight = opts.outHeight;
int orignalWidth = opts.outWidth;
if(orignalWidth > 1000) {
int x = orignalWidth / 2;
int y = orignalHeight / 2;
Bitmap scaled = Bitmap.createScaledBitmap(bp, x, y, true);
bp.recycle();
bp = scaled;
}
return bp;
}