Share Intent


Last Updated:

  1. SoFFacet

    SoFFacet New Member This Topic's Starter

    Joined:
    Jun 7, 2010
    Messages:
    4
    Likes Received:
    0
    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.
     

    Advertisement
  2. IanGClifton

    IanGClifton Well-Known Member

    Joined:
    Feb 7, 2010
    Messages:
    111
    Likes Received:
    19
    Something like this?

    Code (Text):
    1. Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    2. shareIntent.setType("text/plain");
    3. shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Some text");
    4. shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Some other text");
    5.  
    6. startActivity(Intent.createChooser(shareIntent, "Title for chooser"));
    If it's an image/video, you can do it the same way as the gallery:

    Code (Text):
    1. private void startShareMediaActivity(IImage image) {
    2.     boolean isVideo = image instanceof VideoObject;
    3.     Intent intent = new Intent();
    4.     intent.setAction(Intent.ACTION_SEND);
    5.     intent.setType(image.getMimeType());
    6.     intent.putExtra(Intent.EXTRA_STREAM, image.fullSizeImageUri());
    7.     try {
    8.         startActivity(Intent.createChooser(intent, getText(
    9.                 isVideo ? R.string.sendVideo : R.string.sendImage)));
    10.     } catch (android.content.ActivityNotFoundException ex) {
    11.         Toast.makeText(this, isVideo
    12.                 ? R.string.no_way_to_share_image
    13.                 : R.string.no_way_to_share_video,
    14.                 Toast.LENGTH_SHORT).show();
    15.     }
    16. }
     
    SoFFacet likes this.
  3. SoFFacet

    SoFFacet New Member This Topic's Starter

    Joined:
    Jun 7, 2010
    Messages:
    4
    Likes Received:
    0
    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?
     
  4. IanGClifton

    IanGClifton Well-Known Member

    Joined:
    Feb 7, 2010
    Messages:
    111
    Likes Received:
    19
  5. Nyan

    Nyan New Member

    Joined:
    Feb 19, 2010
    Messages:
    1
    Likes Received:
    0
    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"));
    }
     
  6. jmccarthy14

    jmccarthy14 Well-Known Member

    Joined:
    Nov 17, 2009
    Messages:
    219
    Likes Received:
    3
    edited
     
  7. bdtuhin007

    bdtuhin007 New Member

    Joined:
    Nov 17, 2011
    Messages:
    4
    Likes Received:
    0
    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;
     

Share This Page

Loading...