As a Android developer, you might want to integrate android apps with each other. Do you know how that functions? Do you possess knowledge about the way in which they communicate? If no, then for your reference, Android apps possess the ability to integrate as well as communicate with each other. There are ways in which simple data can be sent and received between applications. This can be done by using Intent APIs and the ActionProvider object.
In this article we will cover three ways to share simple data.
- Sending Simple Data to Other Apps
- Receiving Simple Data from Other Apps
- Adding an Easy Share Action
1. Sending Simple Data to Other Apps
Sending & receiving data between apps is one of the most common uses of Intent. It allows for easy and quick sharing of information. One thumb rule to remember is that while constructing an Intent, it is imperative that you specify the action you want it to trigger. There are numerous actions. This includes ACTION_SEND. This indicates that the Intent will send data from one activity to another.
To send data to another activity, we need to specify the data and its type.
Uses of ACTION_SEND
- Send Text Content
- Send Binary Content
- Send Multiple Pieces of Content
1) Send Text Content
Here we use ACTION_SEND action to send text content from one activity to another.
Example:
1
2
3
4
5
|
Intent m_Intent = new Intent();
m_Intent.setAction(Intent.ACTION_SEND);
m_Intent.putExtra(Intent.EXTRA_TEXT, "Sending Text");
m_Intent.setType("text/plain");
startActivity(m_Intent);
|
If there will be any installed application with a filter that matches ACTION_SEND and MIME type text/plain, the Android system will run it. Additionally, if more than one application matches, the Android system displays a dialog or we can say a “chooser” which will allow a user to choose an app.
However, if we call Intent.createChooser(), passing it Intent object, it will always display the chooser.
Example :
1
2
3
4
5
|
Intent m_Intent = new Intent();
m_Intent.setAction(Intent.ACTION_SEND);
m_Intent.putExtra(Intent.EXTRA_TEXT, "Sending Text");
m_Intent.setType("text/plain");
startActivity(Intent.createChooser(m_Intent,"Sharing"));
|
Comments
Post a Comment