Monday, April 15, 2013

[android help] Photo saved to the Pictures directory not being shown on gallery


I am having problems taking a photo in Android and saving it to my gallery. I have looked at every tutorial and I don't see anything wrong with the code. It works on my friends Galaxy S3, but its not working on my Nexus 4. The code is as follows:




public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_taker);

final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/AppPictures/";
File newdir = new File(dir);
newdir.mkdirs();


Button capture = (Button) findViewById(R.id.btnCapture);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

count++;
String file = dir+"MyApp"+count+".jpg";
newFile = new File(file);
try {
newFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

Uri outputFileUri = Uri.fromFile(newFile);

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
}
}); /*...*/


I also have the correct permissions incase anyone thinks its that. I am printing out what Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) is returning, and its /storage/emulated/0/Pictures. Now whats suppose to happen is take a photo and save it in the directory and show it on the gallery app. But I open my gallery app and nothing shows up. I tried testing by creating a new directory, but its not creating the directory. So I am not sure if its the directory not being created or the photo not being stored. My assumption is the directory is not being created.


Edit Thanks to KKD it looks like the file was created, but its just not shown through my Mac file explorer or in the gallery app. But it shows perfectly fine when a photo is taken on a Galaxy S3. Any reason why this happens?



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...