Reputation: 720
I have followed a lot of guides of how to save and reload images to the phone and came to this: In the videos it works but for some reason it does not work for me.
Is there maybe a better version of doing this? And how can I read from this later so I can paste it with Picasso into another ImageView?
(Update: Logcat is saying : Logcat says this: java.io.FileNotFoundException: /storage/emulated/0/LiFit/profileimage.jpg (No such file or directory) but I am clearly creating this folder wiht the mkdir command so why isn´t it workiing ?)
BitmapDrawable drawable = (BitmapDrawable) profilBild.getDrawable();
Bitmap bitmap = drawable.getBitmap();
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File(sdCard.getAbsolutePath()+ "/LiFit");
directory.mkdir();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(directory, fileName);
Toast.makeText(getActivity(), "Pic saved", Toast.LENGTH_LONG).show();
try {
outputStream = new FileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
try {
outputStream.flush();
outputStream.close();
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(outFile));
getContext().sendBroadcast(intent);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Upvotes: 1
Views: 54
Reputation: 720
Apparently you need to change the permissions in the app settings to....
Upvotes: 1