How to share images and text in ACTION_SEND for android Development,

Source: Internet
Author: User

How to share images and text in ACTION_SEND for android Development,

I want to use ACTION_SEND to share images and text. I run the following code. Currently, I can only share images and text. How can I share them?

private Uri imageUri;       private Intent intent;         imageUri = Uri.parse("android.resource://" + getPackageName()                + "/drawable/" + "ic_launcher");        intent = new Intent();        intent.setAction(Intent.ACTION_SEND);        intent.putExtra(Intent.EXTRA_TEXT, "Hello");        intent.putExtra(Intent.EXTRA_STREAM, imageUri);        intent.setType("image/*");        startActivity(intent);


// How can I share images?

Solution

You can share the following code:

String body = "Here is the share content body ";
Intent sharingIntent = new Intent (android. content. Intent. ACTION_SEND );
SharingIntent. setType ("text/plain ");
SharingIntent. putExtra (android. content. Intent. EXTRA_SUBJECT, "Subject Here ");
SharingIntent. putExtra (android. content. Intent. EXTRA_TEXT, plain body );
StartActivity (Intent. createChooser (sharingIntent, getResources (). getString (R. string. pai_using )));

So all your code (image + text) needs to become

private Uri imageUri;private Intent intent; imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher"); intent = new Intent(Intent.ACTION_SEND);//textintent.putExtra(Intent.EXTRA_TEXT, "Hello");//imageintent.putExtra(Intent.EXTRA_STREAM, imageUri);//type of thingsintent.setType("*/*");//sendingstartActivity(intent);


Replace image/* */*

Update:

Uri imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher");Intent shareIntent = new Intent();shareIntent.setAction(Intent.ACTION_SEND);shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);shareIntent.setType("image/jpeg");shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);startActivity(Intent.createChooser(shareIntent, "send"));


Address: http://www.itmmd.com/201411/214.html
This article is organized and published by Meng IT personnel. The reprinted article must indicate the source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.