0

Hello friends i am facing problem with sharing functionality on facebook wall. I am sharing text and image, which is a captured screen of my application. But i unable to share text using following code. Please help me to solve this problem.

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("image/png");
        shareIntent.putExtra(Intent.EXTRA_TITLE, "my awesome caption in the EXTRA_TITLE field");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "your sharing text");
        shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri); // Share
                                                                            // the
                                                                            // image
                                                                            // on
                                                                            // Facebook
        PackageManager pm = mActivity.getPackageManager();
        List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
        for (final ResolveInfo app : activityList)
        {
            if ((app.activityInfo.name).contains(sharingapp))
            {
                c++;
                final ActivityInfo activity = app.activityInfo;
                final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                shareIntent.setComponent(name);
                startActivity(shareIntent);
                break;
            }

        }
Yasmik
  • 57
  • 2
  • 10
  • https://developers.facebook.com/docs/graph-api/reference/v2.2/user/feed?locale=en_GB – andyrandy Jan 09 '15 at 11:00
  • why don t you use FaceBookShareDialog? check Facebook SDK or here https://github.com/b099l3/FacebookImageShareIntent – longi Jan 09 '15 at 11:02
  • Using the intent is fine, however Facebook will not let you set the message as that is against Platform Policies. The user MUST type in the message themselves. – Ming Li Jan 09 '15 at 17:19

1 Answers1

1

Instead of using Intent to share in facebook you should try to use their WebDialog in sharing. Using Intent is not reliable all the time. (Sorry for my english :))

Here is my sample code:

Bundle params = new Bundle();
        params.putString("name", name);
        params.putString("caption", caption);
        params.putString("description", desctription);
        params.putString("picture", image);

        WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(context, Session.getActiveSession(), params))
                .setOnCompleteListener(new WebDialog.OnCompleteListener() {
                    @Override
                    public void onComplete(Bundle values, FacebookException error) {
                        if (error == null) {
                            final String postId = values.getString("post_id");
                            if (postId != null) {
                                ShareDialog.this.dismiss();
                                Toast.makeText(context, "Shared Successfully", Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(context.getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
                            }
                        } else if (error instanceof FacebookOperationCanceledException) {
                            // User clicked the "x" button
                            Toast.makeText(context.getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(context.getApplicationContext(), "Error posting story", Toast.LENGTH_SHORT).show();
                        }
                    }
                })
                .build();
        feedDialog.show();
rubberdont
  • 464
  • 3
  • 15