我试图在 sdcard 上创建一个文件夹并将所有图像保存在那里而不是内部存储器。
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();
}
}
这是我的代码,我尝试了很多东西,但仍然不可能保存在内存 DCIM 文件夹中,为什么?
我得到的输出为
已安装 是的,它是只读的
我没有连接到系统但仍然存在同样的问题我什至尝试重新启动手机,但仍然相同。我正在使用索尼 xperia tipo mobile 4.0.4 操作系统。
请帮助我沮丧我尝试了所有线程。
你们能帮帮我吗
我的权限是
<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().get("data").toString(),Toast.LENGTH_LONG).show();
正在返回一些 android.graphics@422020 一些东西