Sample code of custom functions shared by Android system

Sharing function is a particularly common function in apps. Domestic apps basically support sharing to mainstream social applications such as wechat QQ. As for the implementation of sharing functions, most of them use the third-party share SDK in one step, or there are few shared apps. For example, for a wechat, the sharing module of wechat SDK is usually used. But in fact, Android system has provided us with an implementation method of sharing, and the code is relatively simple as follows

The system provides less than ten lines of code to display the shared list data. After clicking the jump, a series of actions such as sharing the shared content have been completed. This really makes people feel clean, but then there are problems. For example, there are only a few specific apps in my sharing list, and I even put an app first, and the sharing method after clicking Facebook. I want to use the self-contained Facebook, and so on. It's more troublesome to complete some columns of customization functions.

Special treatment for sharing of individual apps

As can be seen from the above code, Google officially defines a one-to-one correspondence rule for shared key values. For example, intent.extra_ Stream corresponds to the URI of the shared picture, intent.extra_ Text corresponds to the shared text. In principle, if the shared apps follow the rules defined by Google, we can share the functions of all apps through the official code. However, the ideal is full and the reality is skinny. For example, Facebook, which is required to share in our project, does not abide by this rule at all. If we want to share with Facebook, we must use its SDK. So we need to click Facebook in the sharing list, which is the sharing logic of Facebook alone.

Step 1: get the data of the shared list

Step 2: build a shared list and define click events

summary

So far, we have completed the expansion and transformation of the sharing mode provided by the Android system. The user-defined sharing list data display, the user-defined sharing form after clicking, etc. can be realized.. In fact, intent.createchooser does a lot of work in this function. If you are interested in children's shoes, you can pick up the source code to see the specific implementation and what work has been done.

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
分享
二维码
< <上一篇
下一篇>>