Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share Text and Image on Facebook using Intent

How to share Text and Image on Facebook, I am writing a Church Application in which i want to allow user to share text and image along with URL.

I am able to share online app link but not able to share text & image, where i am missing ?

my code looks like this:

Button btnFbSharing = (Button) findViewById(R.id.fbSharing);
        btnFbSharing.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                 shareIntent.setType("text/plain");
                 shareIntent.putExtra(android.content.Intent.EXTRA_TITLE, "Church Application");
                 shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.facebook.katana");
                 shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "A new world begin");

                 shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, R.drawable.ic_launcher);
                 PackageManager pm = getApplicationContext().getPackageManager();
                 List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
                 for (final ResolveInfo app : activityList) {
                    if ((app.activityInfo.name).contains("facebook")) {
                        final ActivityInfo activity = app.activityInfo;
                        final ComponentName name = new ComponentName(
                                    activity.applicationInfo.packageName,
                                    activity.name);
                        shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                        shareIntent.setComponent(name);
                        startActivity(shareIntent);
                       }
                 }                  
            }
        });
like image 500
Sophie Avatar asked May 08 '14 12:05

Sophie


1 Answers

Hey I did a lot of research into this as I asked the same question

Basically it is not possible from the facebook app using the package name "com.facebook.katana" as it ignores the extra text when the image is there see this for actual bug but can have links when the image is not there. Very annoying I know.

After a lot of looking about I created my own activity using the facebook sdk 3.14.1 which allows images and text here is the github link to the demo project give it a go and let know if it helps you out.

like image 78
Iain Smith Avatar answered Oct 05 '22 13:10

Iain Smith