How to implement the SHARE function of a Android app?

后端 未结 2 1812
感情败类
感情败类 2020-12-30 17:59

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 e

2条回答
  •  攒了一身酷
    2020-12-30 18:28

    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)
            }
    

提交回复
热议问题