Android Intent Share using external Image url +Text Data

April 27, 2016 , , 5 Comments


public class DataShare {

private Target loadtarget;
Context context;
String DataUrl; // set your message
String ImageUrl;


public DataShare(Context context, String dataUrl) {
this.context = context;
DataUrl = dataUrl;

}

public void ShareAndLoadImage(String url) { //url is your image url

if (loadtarget == null) loadtarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// do something with the Bitmap
try {
handleLoadedBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {

}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {

}

};

Picasso.with(context).load(url).into(loadtarget);
}

public Uri handleLoadedBitmap(Bitmap b) throws IOException {
// do something here
// file donwload temporary
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
if (null != b) {
Log.i("Data", "=>" + b);
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
Uri data = Uri.fromFile(file);
Share(context, data);

}
return Uri.fromFile(file);

}

public void Share(Context context, Uri bmpUri) {
Intent intent = new Intent();
intent .setAction(Intent.ACTION_SEND);

Log.i("bmpurl", "=>" + bmpUri);

intent .putExtra(Intent.EXTRA_TEXT, DataUrl);
intent .putExtra(Intent.EXTRA_SUBJECT, "Subject"); // set your subject here
intent .putExtra(Intent.EXTRA_STREAM, bmpUri);

intent .setType("image/*");

if (!TextUtils.isEmpty(bmpUri + "")) {
context.startActivity(Intent.createChooser(intent , "Share Image"));
}

}

}


How to Use this : new DataShare(Youractivity.this,"Share your MSG").ShareAndLoadImage("http://lorempixel.com/400/200");

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

5 comments:

visitnow56 said...

Can you specify how use this class ??

Thank you for your feedback.

It works really well, but had to use picasso like this:

activity.runOnUiThread(new Runnable() {
public void run() {
Picasso.with(context).load(url).into(loadtarget);
}
});

Thank you for giving your feedback, Now Check Again.

Thank you

Hot-product

Best Watch Store

Popular Posts

Contact Form

Name

Email *

Message *