Reputation: 13555
I am working on a share function in android, from the online tutorial I found the sample code and create the function like that. But it has some drawback(there are too many option if I installed a lot of app), so , in short, I would like to do the following:
Here is my code:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
try {
String newsUrl = Html.fromHtml( URLDecoder.decode(content[0], "UTF-8")).toString().replace("appfunc://share=", "");
String title = Html.fromHtml( URLDecoder.decode(content[1], "UTF-8")).toString();
String newsContent = Html.fromHtml( URLDecoder.decode(content[2], "UTF-8")).toString();
if (!newsContent.equals(""))
newsContent += "...\n\n";
sendIntent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + newsContent + ctx.getResources().getString(R.string.link) + ": " + newsUrl);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
sendIntent.putExtra(Intent.EXTRA_TEXT, ctx.getResources().getString(R.string.share_placeholder));
e.printStackTrace();
};
ctx.startActivity(Intent.createChooser(sendIntent, ctx.getResources().getString(R.string.share_to)));
Upvotes: 2
Views: 636
Reputation: 2110
You can share images using shareIntent like this
private Intent createShareIntent()
{
shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+CreateTempFile(bitmapImage)));
return shareIntent;
}
private File CreateTempFile(Bitmap myBitmap)
{
try
{
File SharingFile = File.createTempFile("OriginalImage", ".jpeg",temporaryFile);
FileOutputStream out = new FileOutputStream(SharingFile);
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return SharingFile;
}
Doing something like this will open all apps that will accept your image.
Upvotes: 2