Android defines several actions, including ACTION_SEND
which indicates that the intent is sending data from one activity to another, even across process boundaries. To send data to another activity, specify the data and its type, the system will identify compatible receiving activities and display them to the user (if there are multiple options) or immediately start the activity (if there is only one option).
Send Text Content
For example, the built-in Browser app can share the URL of the currently-displayed page as text with any application. This is useful for sharing an article or website with friends via email or social networking. Here is the code to implement this type of sharing:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
If there’s an installed application with a filter that matches ACTION_SEND and MIME type text/plain, the Android system will run it; if more than one application matches, the system displays a disambiguation dialog (a “chooser”) that allows the user to choose an app. However, if you call Intent.createChooser(), passing it your Intent object, it returns a version of your intent that will always display the chooser. This has some advantages:
- You can specify the title of the chooser dialog to make it more clearly.
- System will always appear the chooser dialog even the user has chosen a default one.
- If your intent created by
Intent.createChooser
doesn’t match any activity, system will still appear a dialog with the specified title and an error messageNo application can perform this action
. Or for the normal intent, you may get a android runtime error with:Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent
Reference :-
Sending Simple Data to Other Apps