Android : How to make files created by an application readable from computer?

on Friday, December 5, 2014


I am not being able to create an image that is public. I tried to create it in public pictures directory and it gets created there and I can view it from my file explorer in the phone. But the picture is neither picked up by default albums app nor I can see it by connecting the phone to computer. so I suppose the picture is still private. What I require is that the picture must be copied to the computer. Here is the code snippet.



String photoPath = "sdcard/test.jpg";
Bitmap originalBitmap = BitmapFactory.decodeFile(photoPath);
squareBitmap = Bitmap.createBitmap(originalBitmap,0,0,1000,1000);
dvBitmap = squareBitmap.createScaledBitmap(squareBitmap,200,200,false);

//saving bitmap to JPEG in sd card
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
dvBitmap.compress(Bitmap.CompressFormat.JPEG,100,bytes);
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);

File f = new File(path,"output.jpg");
f.setReadable(true);
try {
Log.v(LOG_TAG,"CREATING FILE");
f.createNewFile();

FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
Log.v(LOG_TAG,"FILE CREATED");
} catch (IOException e) {
Log.v(LOG_TAG,"CANNOT CREATE FILE");
e.printStackTrace();
}


Thanks in advance


0 comments:

Post a Comment