0

i want to share image and text using intent but it is not work when facebook intent start it display only image i want to share both text and image

you can check the image here

enter image description here

 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())
                                            {

                                                for(ResolveInfo resInfo : resInfos)
                                                {
                                                    String packageName=resInfo.activityInfo.packageName;
                                                    Log.i("Package Name", packageName);
                                                    if(packageName.contains("com.facebook.katana"))
                                                    {
                                                        String imageurl="/storage/emulated/0/iWally/explosion_3-wallpaper-1024x768.jpg";
                                                        String text="hello how are you";
                                                        Intent intent=new Intent();
                                                        intent.setType("image/*");
                                                        intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
                                                        intent.setAction(Intent.ACTION_SEND);
                                                        intent.putExtra(Intent.EXTRA_TEXT,text);
                                                        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+imageurl.toString()));
                                                        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
                                                {
                                                     Uri uri = Uri.parse("market://details?id=com.facebook.katana"); 
                                                     Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
                                                     startActivity(intent);
                                                    System.out.println("Do not Have facebook");

                                                }
                                            }
Mahesh
  • 1,559
  • 6
  • 27
  • 57

1 Answers1

1

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 "com.facebook.katana" as it ignores the extra text when and 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 to the demo project give it a go and let know if it helps you out.

Community
  • 1
  • 1
Iain Smith
  • 9,230
  • 4
  • 50
  • 61