正試圖在SD卡上創建一個文件夾並將所有圖像保存在那裏,而不是在內部存儲器上。將圖像保存到SD卡文件夾
public class CameraActivity extends Activity {
private static final int CAMERA_PIC_REQUEST = 1111;
private ImageView mImage;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImage = (ImageView) findViewById(R.id.result);
//1
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File image = new File(Environment.getExternalStorageDirectory()+File.separator +"mypics");
Uri fileUri = Uri.fromFile(image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
//2
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
EditText etext = (EditText) findViewById(R.id.editTextLocation);
Toast.makeText(getBaseContext(), data.getExtras().get("data").toString(), Toast.LENGTH_LONG).show();
mImage.setImageBitmap(thumbnail);
etext.setText(data.getExtras().get("data").toString());
//3
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//4
String state=Environment.getExternalStorageState();
Toast.makeText(getBaseContext(), state, Toast.LENGTH_LONG).show();
File file = new File(Environment.getExternalStorageDirectory()+File.separator +"mypics");
if(!file.exists())
if(file.mkdirs())
Log.v("Mobitracker","success");
if (Environment.MEDIA_MOUNTED.equals(state))
Toast.makeText(getBaseContext(), "Yes its read only", Toast.LENGTH_LONG).show();
if (Environment.isExternalStorageRemovable())
Toast.makeText(getBaseContext(), "Yes its internal card", Toast.LENGTH_LONG).show();
//Create New file and name it Image2.PNG
File file1 = new File(file, "Image2.PNG");
try {
file1.createNewFile();
FileOutputStream fo = new FileOutputStream(file1);
//5
fo.write(bytes.toByteArray());
fo.flush();
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
Toast.makeText(getBaseContext(), "Please take snap again", Toast.LENGTH_LONG).show();
}
}
這是我的代碼,我嘗試了很多東西,但仍然不可能保存在internalmemory DCIM文件夾中爲什麼?
作爲
我得到的輸出裝 是它的只讀
我不連接到系統但還是同樣的問題,我甚至嘗試重新啓動手機和所有,但仍然相同。 我使用的是索尼xperia tipo mobile 4.0.4 os。
請幫我沮喪我試過所有的線程。
你們能幫助我,請
我的權限是
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
而且我也能看到位圖圖像圖像視圖,但 Toast.makeText(getBaseContext(),data.getExtras()。獲得( 「數據」)的toString(),Toast.LENGTH_LONG).show()。
正在恢復一些[email protected]一些事情
您是否在清單文件中指定了相關權限? – GrIsHu
http://android-spirit.blogspot.in/2013/07/camera-intent-in-android.html – Nirmal
是的,我有指定的權限 –