Example of using and implementing system “sharing” interface in Android Application

For the promotion and dissemination of applications, many applications have the "sharing" function. After clicking a button, SMS, microblog and other application lists that realize the sharing function will appear. This article mainly introduces how to call the sharing function and how to implement the sharing interface to make your application appear in the sharing list. Android applications can easily complete these functions, which is the greatness of Android. It can easily complete the communication between applications to integrate with each other.

Call sharing function

1. Share text

The sharing function uses the method of implicitly starting the activity. The action here uses action_ SEND。

The effect is shown in Figure 1 below.

2. Change sharing list title

Using the above sharing method, the title of the sharing list is "use the content to complete the operation". Android provides intent. Createchooser (), which can always display the sharing selection list and modify the title content of the sharing list.

Benefits of using intent. Createchooser():

If you callIntent.createChooser() for the intent,Android will always display the chooser. This has some advantages:

The sharing function is not just intent.extra_ Text, or extra_ EMAIL ,EXTRA_ CC ,EXTRA_ BCC ,EXTRA_ Subject. Only the receiver needs to complete the response data acceptance.

3. Share pictures

The sharing function also supports binary content, but most of them are processed images, because the content type is set in shareintent.settype ("image / jpeg"). It can also be of other types and needs the support of the recipient.

4. Share picture list

The sharing function supports not only a single picture, but also a list of pictures. The scope here is too narrow. It should be declared that it is not just pictures.

Realize sharing function

The above is how to call the sharing function. Let's start to write how to realize the sharing function and let our application appear in the sharing list. As mentioned earlier, the sharing function is implemented by implicitly calling Activiy, and the activity needs to declare < intent Filter >.

Declare intent filter

Three types of intent filters are declared above. Of course, there can be more. Here is just an example,

Processing received data declares an intent filter, and the response activity will process the response data. An example is as follows:

By declaring intent filter, the shared receiving function can be completed by processing the received data.

more

The above only gives a brief description of the sharing function. With the upgrade of Android API, there are some new methods to complete the "sharing" function, such as shareactionprovider. Please refer to more.

Demo download: Demo

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>