• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Share Intent

SoFFacet

Lurker
I was wondering how do I create a share intent in my app, like the one in the gallery app that is created when you hit the share button.
 
Something like this?

Code:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Some text");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Some other text");

startActivity(Intent.createChooser(shareIntent, "Title for chooser"));

If it's an image/video, you can do it the same way as the gallery:

Code:
private void startShareMediaActivity(IImage image) {
    boolean isVideo = image instanceof VideoObject;
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType(image.getMimeType());
    intent.putExtra(Intent.EXTRA_STREAM, image.fullSizeImageUri());
    try {
        startActivity(Intent.createChooser(intent, getText(
                isVideo ? R.string.sendVideo : R.string.sendImage)));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(this, isVideo
                ? R.string.no_way_to_share_image
                : R.string.no_way_to_share_video,
                Toast.LENGTH_SHORT).show();
    }
}
 
Thank you, that was very helpful.

I was testing it out by plugging the gallery share code into some other code I have but am experiencing some problems. First of all it wont recognize IImage or VideoObject. I though maybe it could be fixed via auto-importing with Cntl-Shift-O, which is what I usually do when I get this error message, but it didn't work. Any ideas?
 
sharing for facebook didn't work. it just refresh the browser and nothing happened after that. here is my code

public void share() {
final Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Sharing");
intent.putExtra(Intent.EXTRA_TEXT,
"Go to this link " +"http://www.google.com/");

startActivity(Intent.createChooser(intent,
"Select an action for sharing"));
}
 
thnx to read the post. I want to draw graph with multiple lines(here is two case but I have at least 20 cases). I can't understand how intent works in multiple case. can any one please help me?

my Code is >>>>>>>>>>>>>>>>>
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();

switch (TermDimenSnRow)
{
case 1:
int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x values!
int[] y = { 30, 34, 45, 57, 77, 89, 100, 111 ,123 ,145 }; // y values!
TimeSeries series = new TimeSeries("Line1");
for( int i = 0; i < x.length; i++)
{
series.add(x, y);
}
dataset.addSeries(series);
XYSeriesRenderer renderer = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
break
case 2:
int[] x2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x values!
int[] y2 = { 145, 123, 111, 100, 89, 77, 57, 45, 34, 30}; // y values!
TimeSeries series2 = new TimeSeries("Line2");
for( int i = 0; i < x2.length; i++)
{
series2.add(x2, y2);
}
dataset.addSeries(series2);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer2);

break;
}

Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph");
return intent;
 
Back
Top Bottom