Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement the SHARE function of a Android app?

Tags:

android

Sometimes we can see that after clicking some "share" button, a list of sharable ways displays. And that list seems generated dynamically and not hard-coded.

For example, I have SpringPad installed on my phone, and some apps' sharing function is able to share the content via SpringPad, but how could it know that I have SpringPad?

How to implement such a function? Thanks.

like image 574
shihpeng Avatar asked Apr 13 '11 07:04

shihpeng


People also ask

What is Android app simple sharing?

2020. Simple Sharing feature is an easier way to share large-capacity files with your friends via Contacts. Simple sharing is available in all applications that can use the Share via feature. (


1 Answers

Here is the actual code from my Android app BBC News that does this. It shares the URL to the page. If the user has Facebook or Twitter apps installed they will be offered the opportunity to share to those services, as well as email etc.

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, pageUrl);

        try {
          startActivity(Intent.createChooser(intent, "Select an action"));
        } catch (android.content.ActivityNotFoundException ex) {
          // (handle error)
        }
like image 97
Jim Blackler Avatar answered Oct 12 '22 18:10

Jim Blackler