I am using this code to share an image:
File file = ImageLoader.getInstance().getDiskCache().get(imageUrl);
if (file != null && file.exists()) {
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(Intent.createChooser(intent, "Send"));
} else {
Toast.makeText(context, "Image cannot be shared", Toast.LENGTH_SHORT).show();
}
I used UIL to load the image previously, so mageLoader.getInstance().getDiskCache().get(imageUrl); returns the image file from disk cache.
Gmail, Hangouts, Messages, Drive etc can grab the file but on Google+, the grabbed is not gotten while Whatsapp says "This format is not supported". However if I save the file to Downloads folder and share via Gallery app, the same image is picked by both Google+ and Whatsapp.
You can try to save the file to the external cache, it's working for me. Example with Glide:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("image/*");
Glide.with(getContext())
.load("http://...url.here...")
.asBitmap()
.into(new SimpleTarget<Bitmap>(500, 500) {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
try {
File file = new File(getContext().getExternalCacheDir(), "file_to_share.png");
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
resource.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
getContext().startActivity(Intent.createChooser(sendIntent, ""));
} catch (IOException e) {
Log.e("Share", e.getMessage(), e);
} finally {
}
}
});
In case you're using Universal Image Loader, I applied the accepted answer to save the image and delete it as soon as the user returns from sharing:
private File saveImage(String imageUri, String fileName) {
File file = new File(this.getExternalCacheDir(), fileName);
InputStream sourceStream = null;
File cachedImage = ImageLoader.getInstance().getDiskCache().get(imageUri);
if (cachedImage != null && cachedImage.exists()) {
Log.d(TAG, "Cache exists");
try {
sourceStream = new FileInputStream(cachedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "Cache doesn't exist");
}
if (sourceStream != null) {
Log.d(TAG, "SourceStream is not null");
try {
OutputStream targetStram = new FileOutputStream(file);
try {
try {
IoUtils.copyStream(sourceStream, targetStram, null);
} catch (IOException e) {
e.printStackTrace();
}
} finally {
try {
targetStram.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
sourceStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
Log.d(TAG, "SourceStream is null");
Toast.makeText(this, "Image cannot be shared", Toast.LENGTH_SHORT).show();
}
return file;
}
private void shareImage(String imageUrl, String fileName) {
if (isSDReadableWritable()) {
file = saveImage(imageUrl, fileName);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(Intent.createChooser(intent, "Send"), 20);
} else {
Toast.makeText(this, "Storage cannot be accessed", Toast.LENGTH_SHORT).show();
}
}
To delete the file just override onActivityResult and it'll be deleted immediately after sharing
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 20 && file != null) {
boolean isDelete = file.delete();
Log.d(TAG, "isDelete is " + isDelete);
}
}
Related
I need to share both an image and some text via WhatsApp, using an Intent on Android.
Uri imageUri = Uri.parse(Filepath);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT, "My sample image text");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageUrl));
shareIntent.setType("image/png");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Kindly install whatsapp first");
}
I’m using the code above, but it throws a 'File format not supported' error while sharing.
You can try like this
public static void shareOnWhatsapp(Context context, String str) {
Uri parse = Uri.parse(str);
Intent intent = new Intent();
intent.setAction("android.intent.action.SEND");
intent.setPackage("com.whatsapp");
String stringBuilder = context.getResources().getString(R.string.play_more_app) +
context.getPackageName();
intent.putExtra("android.intent.extra.TEXT", stringBuilder);
intent.putExtra("android.intent.extra.STREAM", parse);
intent.setType("image/*");
intent.addFlags(1);
try {
context.startActivity(intent);
} catch (Exception unused) {
setToast(context, context.getResources().getString(R.string.whatsapp_not_installed));
}
}
I used this function to share images it's working I hope it's work you too.
Edit
Add this dependency for converting URL to bitmap
implementation 'com.github.bumptech.glide:glide:4.14.2'
Use this function to get Image URI to share
private Uri getImageURI(Bitmap image) {
File imagesFolder = new File(getCacheDir(), "images");
Uri uri = null;
try {
imagesFolder.mkdirs();
File file = new File(imagesFolder, "shared_image.png");
FileOutputStream stream = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 90, stream);
stream.flush();
stream.close();
uri = FileProvider.getUriForFile(this, getPackageName() + ".provider", file);
} catch (IOException e) {
Log.d("TAG", "IOException while trying to write file for sharing: " + e.getMessage());
}
return uri;
}
Use this function for share Image on WhatsApp
public static void shareOnWhatsapp(Context context, Uri uri) {
Intent intent = new Intent();
intent.setAction("android.intent.action.SEND");
intent.setPackage("com.whatsapp");
String stringBuilder = "Your String Or Message" +
context.getPackageName();
intent.putExtra("android.intent.extra.TEXT", stringBuilder);
intent.putExtra("android.intent.extra.STREAM", uri);
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(intent);
} catch (Exception unused) {
Toast.makeText(context, "whatsapp not installed", Toast.LENGTH_SHORT).show();
}
}
Uses like this
findViewById(R.id.btnShare).setOnClickListener(v -> {
Glide.with(this).asBitmap().load( /*Your URL*/ "https://drinkprime.in/images/smart_water_purifier.jpg").into(new CustomTarget<Bitmap>() {
#Override
public void onResourceReady(#NonNull Bitmap resource, #Nullable Transition<? super Bitmap> transition) {
Bitmap bitmap = resource;
shareOnWhatsapp(MainActivity.this, getImageURI(bitmap));
}
#Override
public void onLoadCleared(#Nullable Drawable placeholder) {
}
});
});
It's Working now completely
This is my wallpapers downloading code. It works on only Google Photo. Please give me the simplest code to single click download the wallpapers.
How to download wallpaper in one click into gallery automatically?
private void downloadWallpaper(final Wallpaper wallpaper) {
((Activity) mCtx).findViewById(R.id.progressbar).setVisibility(View.VISIBLE);
Glide.with(mCtx)
.asBitmap()
.load(wallpaper.url)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
((Activity) mCtx).findViewById(R.id.progressbar).setVisibility(View.GONE);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = saveWallpaperAndGetUri(resource, wallpaper.id);
if (uri != null) {
intent.setDataAndType(uri, "image/*");
mCtx.startActivity(Intent.createChooser(intent, "Islamic Writes"));
}
}
}
);
}
private Uri saveWallpaperAndGetUri(Bitmap bitmap, String id) {
if (ContextCompat.checkSelfPermission(mCtx, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat
.shouldShowRequestPermissionRationale((Activity) mCtx, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Intent intent = new Intent();
intent.setAction( Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", mCtx.getPackageName(), null);
intent.setData(uri);
mCtx.startActivity(intent);
} else {
ActivityCompat.requestPermissions((Activity) mCtx, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
}
return null;
}
File folder = new File(Environment.getExternalStorageDirectory().toString() + "/Download");
folder.mkdirs();
File file = new File(folder, id + ".jpg");
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
Intent intent = new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE );
mCtx.sendBroadcast(intent);
return FileProvider.getUriForFile( mCtx, BuildConfig.APPLICATION_ID +".provider",file );
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
I have tried everything but Image is not showing in Gallery, but its
saved in Internal Storage. I have tried several tutorials, but unable
to solve it .How can I implement it so that it is shown in Gallery
download.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (ContextCompat.checkSelfPermission(FullScreenActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
//to get the image from the ImageView (say iv)
BitmapDrawable draw = (BitmapDrawable) fullscreenimage.getDrawable();
Bitmap bitmap = draw.getBitmap();
FileOutputStream outStream = null;
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/IslamicStatusPics");
Log.e("DIR", String.valueOf(dir));
dir.mkdirs();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
try {
outStream = new FileOutputStream(outFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
try {
outStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
AlertDialog alertDialog = new AlertDialog.Builder(FullScreenActivity.this).create();
alertDialog.setTitle("Success");
alertDialog.setMessage("Image Saved to IslamicStatusPics Folder Successfully !");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File("/storage/emulated/0/IslamicStatusPics/"))));
// Toast.makeText(getApplicationContext(), "Image Saved to IslamicStatusPics Successfully !", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
// intent.setData(Uri.fromFile(dir));
// sendBroadcast(intent);
}else {
requestStoragePermission();
}
Please help me Guide in the Right Path. Thanks
You can try below code with saved file uri:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent mediaScanIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(Uri.fromFile(outFile)); //change here
activity.sendBroadcast(mediaScanIntent);
} else {
activity.sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
I basically want to hide the imagesthe user clicks in my app from the user in the gallery, display them in a small imageview and send it to the server. I am doing it the below way. However Bitmap Factory decode gives me a null bitmap I dont know why. Any help would be appreciated.
For creating file to save image to and opening camera intent;
public void openCamera(View view) {
PermissionsClass.checkPermissions(DIalogActivity.this, AppConfig.REQ_WRITE_ACCESS);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(DIalogActivity.this.getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
//resizeFile(mCurrentPhotoPath);
photoURI = FileProvider.getUriForFile(DIalogActivity.this,
"com.example.sandithaa.nfcreader.fileprovider",
photoFile);
Log.i("photouri", String.valueOf(photoURI));
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
} else {
List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
startActivityForResult(intent, 1);
} else {
Toast.makeText(this, "Camera cannot be opened.", Toast.LENGTH_SHORT).show();
}
}
}
For creating the file:
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
mCurrentPhotoPath = image.getAbsolutePath();
Log.i("filepathin createbefore", mCurrentPhotoPath);
return image;
}
For uploading to the server :
private void uploadFile() {
final String path;
Log.i("uplaod pdf", "pdf");
Random r = new Random();
int randomNo = r.nextInt(100000000 + 1);
String name = "IMG" + randomNo;
//getting the actual path of the image
// path = FilePath.getPath(this, photoURI);
// Log.i("path is",path);
Log.i("current parh", mCurrentPhotoPath);
try {
final String uploadId = UUID.randomUUID().toString();
Log.i("in uplaod 1", String.valueOf(priority.getSelectedItem()));
Log.i("proti", incidentEt.getText().toString());
//Creating a multi part request
new MultipartUploadRequest(this, uploadId, "http://technobyteinfo.in/filter-coffee/uploadAll.php")
.addFileToUpload(mCurrentPhotoPath, "pdf") //Adding file
.addParameter("name", name)
.addParameter("description", incidentEt.getText().toString().trim())
.addParameter("priority" +
"", priority.getSelectedItem().toString())
.addParameter("time", time)
.addParameter("longitude", MySharedPreferences.retrievePreferences("longitude", getApplicationContext(), "00.00"))
.addParameter("latitude", MySharedPreferences.retrievePreferences("latitude", getApplicationContext(), "00.00"))
.addParameter("deviceid", GetDeviceId.getMyAndroidDeviceId(getApplicationContext()))
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.setDelegate(new UploadStatusDelegate() {
#Override
public void onProgress(Context context, UploadInfo uploadInfo) {
}
#Override
public void onError(Context context, UploadInfo uploadInfo, Exception exception) {
Toast.makeText(context, "File could not be uploaded.", Toast.LENGTH_SHORT).show();
Log.i("exceptipn", exception.getMessage());
}
#Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
Log.i("error is", serverResponse.getBodyAsString());
JSONObject jObj = null;
try {
jObj = new JSONObject(serverResponse.getBodyAsString());
boolean error = jObj.getBoolean("error");
if (error == false) {
Toast.makeText(context, "Details saved successfully.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "File could not be uploaded.", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
}
})
.startUpload(); //Starting the upload
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Trying to compress the images this way:
public void compressImage() {
try {
OutputStream outStream = null;
Log.i("imagefiename",imageFileName);
outStream = new FileOutputStream(mCurrentPhotoPath);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 8;
bitmap = BitmapFactory.decodeFile(imageFileName ,bmOptions);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, outStream);
outStream.flush();
outStream.close();
Log.i("file path compress", mCurrentPhotoPath);
} catch (Exception e) {
Log.i("exception", e.toString());
}
}
My onActivityResult after camera intent comes back:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
compressImage();
Picasso.get().load(photoURI).resize(300,300).into(imageView);
}
I have been struggling to send text from my app to Twitter.
The code below works to bring up a list of apps such as Bluetooth, Gmail, Facebook and Twitter, but when I select Twitter it doesn't prefill the text as I would have expected.
I know that there are issues around doing this with Facebook, but I must be doing something wrong for it to not be working with Twitter.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Example Text");
startActivity(Intent.createChooser(intent, "Share Text"));
I'm using this snippet on my code:
private void shareTwitter(String message) {
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test.");
tweetIntent.setType("text/plain");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for (ResolveInfo resolveInfo : resolvedInfoList) {
if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
tweetIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(tweetIntent);
} else {
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, message);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://twitter.com/intent/tweet?text=" + urlEncode(message)));
startActivity(i);
Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show();
}
}
private String urlEncode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.wtf(TAG, "UTF-8 should always be supported", e);
return "";
}
}
Hope it helps.
you can simply open the URL with the text and Twitter App will do it. ;)
String url = "http://www.twitter.com/intent/tweet?url=YOURURL&text=YOURTEXT";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
and it will also open the browser to login at the tweet if twitter app is not found.
Try this, I used it and worked great
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/intent/tweet?text=...."));
startActivity(browserIntent);
First you have to check if the twitter app installed on the device or not then share the text on twitter:
try
{
// Check if the Twitter app is installed on the phone.
getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Your text");
startActivity(intent);
}
catch (Exception e)
{
Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show();
}
For sharing text and image on Twitter, more controlled version of code is below, you can add more methods for sharing with WhatsApp, Facebook ... This is for official App and does not open browser if app not exists.
public class IntentShareHelper {
public static void shareOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.twitter.android");
intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : "");
if (fileUri != null) {
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("image/*");
}
try {
appCompatActivity.startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
ex.printStackTrace();
showWarningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found));
}
}
public static void shareOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...}
private static void showWarningDialog(Context context, String message) {
new AlertDialog.Builder(context)
.setMessage(message)
.setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setCancelable(true)
.create().show();
}
}
For getting Uri from File, use below class:
public class UtilityFile {
public static #Nullable Uri getUriFromFile(Context context, #Nullable File file) {
if (file == null)
return null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file);
} catch (Exception e) {
e.printStackTrace();
return null;
}
} else {
return Uri.fromFile(file);
}
}
// Returns the URI path to the Bitmap displayed in specified ImageView
public static Uri getLocalBitmapUri(Context context, ImageView imageView) {
Drawable drawable = imageView.getDrawable();
Bitmap bmp = null;
if (drawable instanceof BitmapDrawable) {
bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
} else {
return null;
}
// Store image to default external storage directory
Uri bmpUri = null;
try {
// Use methods on Context to access package-specific directories on external storage.
// This way, you don't need to request external read/write permission.
File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = getUriFromFile(context, file);
} catch (IOException e) {
e.printStackTrace();
}
return bmpUri;
}
}
For writing FileProvider, use this link: https://github.com/codepath/android_guides/wiki/Sharing-Content-with-Intents