I have got trouble when take a picture using the Samsung Galaxy s6, and get the bitmap from that. It works correctly on other platform like Galaxy Note and s5, LG G@, and a Blackberry PRIV. But now, I have got a trouble when I work on Samsung Galaxy s6. Please give me solution who has got some experiences on that.
My code is below...
String mCurrentPhotoPath;
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "IMG_" + timeStamp + "_";
File albumF = getAlbumDir();
if (albumF == null){
return null;
}
File imageF = File.createTempFile(imageFileName, ".jpg", albumF);
mCurrentPhotoPath = "file:" + imageF.getAbsolutePath();
return imageF;
}
private File getAlbumDir() {
File storageDir = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
storageDir = new File(
Environment.getExternalStorageDirectory()
+ "/dcim/"
+ "test"
);
if (storageDir != null) {
if (!storageDir.mkdirs()) {
if (!storageDir.exists()) {
Log.d("test", "failed to create directory");
CommonFunc.ShowAlertDialog(this,"test", "failed to create directory",null);
return null;
}
}
}
} else {
Log.v(getString(R.string.app_name), "External storage is not mounted READ/WRITE.");
CommonFunc.ShowAlertDialog(this, getString(R.string.app_name), "External storage is not mounted READ/WRITE.", null);
}
return storageDir;
}
public void showUserImgCameraDialog(View v) {
Intent takePicture = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
pFile = null;
try {
pFile = createImageFile();
} catch (IOException e) {
CommonFunc.ShowToast(this, "creatimagefile issue" + mCurrentPhotoPath);
}
if (pFile != null) {
takePicture.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(pFile));
try {
startActivityForResult(takePicture,
100);
} catch (Exception e) {
CommonFunc.ShowAlertDialog(this, "test", "No Camera on Device:" + e.toString(), null);
}
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK) {//upload user image from camera
imageView = (ImageView) findViewById(R.id.ivAvatar);
try {
try {
FileInputStream in = new FileInputStream(pFile);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 10;
mCurrentPhotoPath = pFile.getAbsolutePath();
CommonFunc.ShowToast(this, mCurrentPhotoPath);
Bitmap _bmp = BitmapFactory.decodeStream(in, null, options);
imageView.setImageBitmap(_bmp);
} catch (FileNotFoundException e) {
e.printStackTrace();
CommonFunc.ShowAlertDialog(this, "test", "ImageFileNotFound", null);
}
}catch (Exception e){}
}
callbackManager.onActivityResult(requestCode, resultCode, data);
}
I can't see the onActivity Camera Screen, and I think it is because the createImageFile path(mCurrentPhotoPath) is not correct on Samsung Galaxy S6. But this code works on other platforms except Samsung Galaxy S6.
If someone has got exp, please let me know. Thanks.
ps: I think it is because I am using the external storage on this code. But Samsung Galaxy S6 doesn't support the external storage like SD memory card. *****So I would like to know how to create temp file on internal storage of the Samsung Galaxy S6.*****