Android and Facebook share intent

前端 未结 12 2234
闹比i
闹比i 2020-11-22 13:02

I\'m developing an Android app and am interested to know how you can update the app user\'s status from within the app using Android\'s share intents.

Having looked

12条回答
  •  没有蜡笔的小新
    2020-11-22 13:27

    Seems in version 4.0.0 of Facebook so many things has changed. This is my code which is working fine. Hope it helps you.

        /**
         * Facebook does not support sharing content without using their SDK however
         * it is possible to share URL
         *
         * @param content
         * @param url
         */
        private void shareOnFacebook(String content, String url)
        {
            try
            {
                // TODO: This part does not work properly based on my test
                Intent fbIntent = new Intent(Intent.ACTION_SEND);
                fbIntent.setType("text/plain");
                fbIntent.putExtra(Intent.EXTRA_TEXT, content);
                fbIntent.putExtra(Intent.EXTRA_STREAM, url);
                fbIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                fbIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                fbIntent.setComponent(new ComponentName("com.facebook.katana",
                        "com.facebook.composer.shareintent.ImplicitShareIntentHandler"));
    
                startActivity(fbIntent);
                return;
            }
            catch (Exception e)
            {
                // User doesn't have Facebook app installed. Try sharing through browser.
            }
    
            // If we failed (not native FB app installed), try share through SEND
            String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + url;
            SupportUtils.doShowUri(this.getActivity(), sharerUrl);
        }
    

提交回复
热议问题