How can one share a complete loaded image set in an ImageView along side with text to whats app using intents and Glide.....I looked a lot but i only found for Picasso Library here is the link or if the link is dead google this phrase :
Sharing Content with Intents 路 codepath_android_guides Wiki.htm
If you really want to share the same, use .asBitmap() and save the Bitmap as a file or don't use .asBitmap() and render the view onto a Bitmap and then compress onto a file to be shared in the intent.
@TWiStErRob .... OK i got your it makes a lot of sense. the image would look crappy.
But i have mad a work around the results or image i am sending or sharing to my whats app they seem to be OK i guess it has to do with the glide cache policy i would have mad but below this what i did. i used the glide call back functionality of getting the image and sharing it given that the image or bitmap has loaded fully.
EventfaceImage is the imageview i defined,
Glide.with(context).load(uri).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL)
.dontAnimate().into(new BitmapImageViewTarget(EventfaceImage) {
@Override
public void onResourceReady(final Bitmap bmp, GlideAnimation anim) {
share.setVisibility(View.VISIBLE);
EventfaceImage.setImageBitmap(bmp);
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
menu_float.close(true);
prepareShareIntent(bmp);
}
});
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
}
});
then the prepareShareIntent(); function
private void prepareShareIntent(Bitmap bmp) {
Uri bmpUri = getLocalBitmapUri(bmp); // see previous remote images section
// Construct share intent as described above based on bitmap
shareIntent = new Intent();
shareIntent.setPackage("com.whatsapp");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.shared_via) );
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Opportunity"));
}
then the getLocalBitmapUri(); it returns a Uri as shown in the method above;
private Uri getLocalBitmapUri(Bitmap bmp) {
Uri bmpUri = null;
File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
bmpUri = Uri.fromFile(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return bmpUri;
}
This works for me in API 22. So i hope this will help someone, but also i have not tested in all the api in Android. If doesn't please let me know and i will see what i can hack. also feel free to better the code and share whats working for you too.
Yep, this is what I meant; a few notes:
setResource instead of onResourceReady.@TWiStErRob this was directed to those who wanted to share to whats app directly as the questions states but i do get what you mean , the developer will have to check first if whats app is installed. and the the developer will have to set a home cleaning mechanism to clear cache off the main thread as it will throw an exception if done on the main UI.
All in all @TWiStErRob thanks for participating in this.
Hello,
onClick is not working, << Its working now after declaring share Button in the OnCreateView.
is there a similar way to share GIF
@keeptesting what's wrong with #459?
@TWiStErRob thank you for your suggestion, i have an error: the file format is not supported, even after implementing new ImageHeaderParser(new ParcelFileDescriptor.AutoCloseInputStream(openFile(uri, "r"))).getType() in ImageFileProvider
and CacheStrategy.All
@kinsleykajiva what is menu_float.close(true);
@SagarKhengat its just a FAB library that i was using to close the child FAB items thus all but has nothing to do with the glide thing
Reopening this as a reminder to look at Glide-Whatsapp interation, no-one really confirmed it working and many complained. It may still take a while until I get to this, but it's in the queue.
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Hello how to send data using intent in android
Hello how to send data using intent in android
Hello @Archirayan41 you can do it by following way.
Source class:
Intent myIntent = new Intent(this, NewActivity.class);
myIntent.putExtra("firstName", "Your First Name Here");
myIntent.putExtra("lastName", "Your Last Name Here");
startActivity(myIntent)
Destination Class (NewActivity class):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
Intent intent = getIntent();
String fName = intent.getStringExtra("firstName");
String lName = intent.getStringExtra("lastName"); }
or in regards of the glide image all you can do is:
GlideBitmapDrawable bitmapDrawable = (GlideBitmapDrawable)imageViewPreview.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
// Save this bitmap to a file.
File cache = getContext().getExternalCacheDir();
File sharefile = new File(cache, "toshare.png");
Log.d("share file type is", sharefile.getAbsolutePath());
try {
FileOutputStream out = new FileOutputStream(sharefile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (IOException e) {
Log.e("ERROR", String.valueOf(e.getMessage()));
}
// Now send it out to share
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + sharefile));
startActivity(Intent.createChooser(share,
"Share This Image with"));