Reputation: 1340
I use the following code to obtain Photos which are stored in a SD-card folder. which is working fine. BUT the photos are as well stored in the SD-Cards image folder and showed in androids photo gallery. Why?
thanks in advance!
public class Foto extends Activity implements SurfaceHolder.Callback,
OnClickListener {
private static final int CAMERA_ACTIVITY = 1;
private static final int TAKE_PICTURE = 1;
File archive, root, folder;
String fec;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
String path = Environment.getExternalStorageDirectory().getName()
+ File.separatorChar + "TEST" + "/"
+ "test.jpg";
archive = new File(path);
try {
if (archive.exists() == false) {
archive.getParentFile().mkdirs();
archive.createNewFile();
}
if (archive.exists() == true) {
archive.createNewFile();
}
} catch (IOException e) {
Log.e(ACTIVITY_SERVICE, "Could not create file.", e);
}
Log.i(ACTIVITY_SERVICE, path);
Uri _fileUri = Uri.fromFile(archive);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, _fileUri);
startActivityForResult(intent, TAKE_PICTURE);
setResult(RESULT_OK, intent);
finish();
} else {
new AlertDialog.Builder(Foto.this)
.setMessage(
"External Storeage (SD Card) is required.\n\nCurrent state: "
+ storageState).setCancelable(true)
.create().show();
finish();
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
}
Upvotes: 0
Views: 589
Reputation: 6397
On most devices MediaStore.ACTION_IMAGE_CAPTURE saves to the Gallery in addition to anything else it does, even if you don't ask for a file back, just a URI. I know on Nexus 7 it doesn't do this, however, which really sucks how the behavior is just magically different and is annoying to work around. Anyway, also note that the Gallery actually shows anything anywhere on the SD card without a .nomedia file, though, provided the media scanner has caught up.
Upvotes: 1