Sharing content to other Apps in Android

less than 1 minute read

Sharing is sending content such as text, files, or images to other apps.

Sharing Text

Intent shareIntent = ShareCompat.IntentBuilder.from(activity)
  .setType("text/plain")
  .setText(shareText)
  .getIntent();
if (shareIntent.resolveActivity(getPackageManager()) != null) {
  startActivity(shareIntent);
}

Sharing HTML Text

Intent shareIntent = ShareCompat.IntentBuilder.from(activity)
  .setType("text/html")
  .setHtmlText(shareHtmlText)
  .setSubject("Definitely read this")
  .addEmailTo(importantPersonEmailAddress)
  .getIntent();

Receiving Text

``` java <activity android:name=”.ShareActivity”>

<action android:name=”android.intent.action.SEND”/> <category android:name=”android.intent.category.DEFAULT”/> <category android:name=”android.intent.category.BROWSABLE”/> <data android:mimeType=”text/plain”/>

</activity>

Tags:

Categories:

Updated:

Leave a comment