Reputation: 131
I everyone, I have a problem. I have to send an image to whatsapp from my application. I downloaded the image in bitmap format. After I convert the bitmap format in jpg and I try to send the image. But whatsapp doesn't receive any data.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
Bitmap bmp = getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
File f = new File(getAppContext().getCacheDir() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(stream.toByteArray());
fo.flush();
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
shareIntent.putExtra(Intent.EXTRA_STREAM, f.getPath());
myShareActionProvider.setShareIntent(shareIntent);
I have insert into manifest all the permissions. How Can I fix it? Thanks.
PS. I use min sdk 17 and max sdk 24
Upvotes: 0
Views: 542
Reputation: 3518
WhatsApp doesn't have access to the directory returned by getCacheDir(), only your app does. Try doing it like this instead:
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
For this to work, you need to declare the WRITE_EXTERNAL_STORAGE permission in your manifest.xml file. Like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Upvotes: 1