0

I tried this code, I chose Facebook app and went to post page, but the chosen text does not get displayed.

public void onShareClick(View v){
    List<Intent> targetShareIntents=new ArrayList<Intent>();
    Intent shareIntent=new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    List<ResolveInfo> resInfos=getPackageManager().queryIntentActivities(shareIntent, 0);
    if(!resInfos.isEmpty()){
        System.out.println("Have package");
        for(ResolveInfo resInfo : resInfos){
            String packageName=resInfo.activityInfo.packageName;
            Log.i("Package Name", packageName);
            if( packageName.contains("com.facebook.katana")){
                Intent intent=new Intent();
                intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT, "Text");
                intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                intent.setPackage(packageName);
                targetShareIntents.add(intent);
            }
        }
        if(!targetShareIntents.isEmpty()){
            System.out.println("Have Intent");
            Intent chooserIntent=Intent.createChooser(targetShareIntents.remove(0), "Choose app to share");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
            startActivity(chooserIntent);
        }else{
            System.out.println("Do not Have Intent");
            showDialaog(this);
        }
    }
}

Why doesn't the chosen text to share Display on facebook? I read Facebook's policy and they do not allow this, yet other applications are able to do so. Is there some way I can achieve that?

crystalfrost
  • 261
  • 1
  • 3
  • 14
Samah
  • 61
  • 1
  • 10
  • 1
    Possible duplicate of [Android Share - Facebook SDK - ShareActionProvider](http://stackoverflow.com/questions/13371663/android-share-facebook-sdk-shareactionprovider) – Larry Schiefer May 03 '16 at 16:36

1 Answers1

0

Try this:

public void setupFacebookShareIntent() {

        ShareDialog shareDialog;

        FacebookSdk.sdkInitialize(getApplicationContext());
        shareDialog = new ShareDialog(this);

        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentTitle("YOUR TITLE")
                .setContentDescription("YOUR DESCRIPTION")
                .setContentUrl(Uri.parse("http://xxxx.com/"))
                .setImageUrl(Uri.parse("http://xxxx.com/"))
                .build();

        shareDialog.show(linkContent);
    }
Sin
  • 83
  • 9