使用三星 Galaxy s6 拍照并从中获取位图时遇到问题。它可以在 Galaxy Note 和 s5、LG G@ 和 Blackberry PRIV 等其他平台上正常工作。但是现在,我在三星 Galaxy s6 上工作时遇到了麻烦。请给我解决方案谁有一些经验。
我的代码如下...
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);
}
我看不到 onActivity 相机屏幕,我认为这是因为三星 Galaxy S6 上的 createImageFile 路径(mCurrentPhotoPath)不正确。但此代码适用于三星 Galaxy S6 以外的其他平台。
如果有人有经验,请告诉我。谢谢。
ps:我认为是因为我在这段代码上使用了外部存储。但三星 Galaxy S6 不支持 SD 存储卡等外部存储。*****所以我想知道如何在三星 Galaxy S6 的内部存储上创建临时文件。*****