Reputation: 519
Been a long time since I needed help, but here I am........anyway
In my app, the user has the ability to take a photo of an animal or to select an already existing image from their gallery to save that image.
The code works well with tHE Pixels and Samsungs and every other non-kindle I test with. However it fails to save either an image selected from the gallery (which does populate the correct spot in the app) so I know it's there and it fails to save an image taken with the built-in camera which also correctly populates the imageview in the app.
Here's the source code
save_image.setOnClickListener(v->{
Bitmap bitmap = ((BitmapDrawable) animal_image_view.getDrawable()).getBitmap();
Toast.makeText(getBaseContext(),"Save Image Pressed ", Toast.LENGTH_LONG).show();
if (!pictureDir.exists()) {
pictureDir.mkdirs();
}
String fileName = editName +"-"+ System.currentTimeMillis() + ".jpg";
File file = new File(pictureDir, fileName);
// Step 3: Save the Bitmap to the file
try (FileOutputStream outputStream = new FileOutputStream(file)) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.flush();
// Step 4: Notify the Media Scanner (optional, to show the image in Gallery)
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(file);
//Successful let's save the file name to the record
Toast.makeText(getBaseContext(),"File Name to Save "+ fileName, Toast.LENGTH_LONG).show();
UpdateclientRecord updateRecord = new UpdateClientRecord("", "","",
"", "", "", "", 0,
"", "",fileName);
UpdateclientRecord(updateRecord,WhatRecordIsThis);
Toast.makeText(getBaseContext(),"Image Saved "+ fileName, Toast.LENGTH_LONG).show();
mediaScanIntent.setData(uri);
animal_image_view.getContext().sendBroadcast(mediaScanIntent);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(),"Save Failed ", Toast.LENGTH_LONG).show();
}
//startActivityForResult(saveIntent, RESULT_SAVE_IMG);
});
I've searched our old friend Google and looked at the Amazon docs - but can't seem to narrow things down.I'm certain I'm missing a permission or something but what it is I'm at a loss.
Any suggestions are greatly appeciated TIA
Upvotes: 0
Views: 27
Reputation: 519
Problem solved, the Kindle hadn't given the app permission to use the storage, once I changed the settings on the device it worked fine. Now all I have to do is make sure to request permission in the app and all is good.
Upvotes: 0