android tutorial - Use of Intent to Share text in Android Intent | Developer android - android app development - android studio - android app developement



Use of Intent to Share text

  • On calling, an application chooser dialog will appear and by selecting an application you can share your content with it.

For calling use this line of code in your program class:

share(context, "This is a test message", "Test Subject")
click below button to copy code from our android learning website - android tutorial - team

Function's definition:

public static void share (Context context, String text, String subject, String title, String dialogHeaderText) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    intent.putExtra(Intent.EXTRA_TITLE, title);
    context.startActivity(Intent.createChooser(intent, dialogHeaderText));
}
click below button to copy code from our android learning website - android tutorial - team

Related Searches to Use of Intent to Share text in Android Intent