0

I am new on progamming android and I have some problems on sharing contents. I did an android app that involves a test. In the last activity I'd like to offer the opportunity to share the users results via shareintent, here a frame of the code:

    display=  (TextView) findViewById (R.id.tvDisplay);
    display.setText("Well Done, your score is" + score ); //score is an int
    sharebutton= (Button)findViewById(R.id.sharebutton);
    sharebutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            results = display.getText().toString();
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT,"My score in the test is" + results);
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, "TEST");
            startActivity(Intent.createChooser(shareIntent, "Share.."));
        }
    });

The problem is that when I click on the button, I can share the exact text in all of sharer tools (email, wapp, etc..), but not through Facebook. Why? I tried to allow to post image and text on the FB wall but I can't give the exact path of the image that is on the drawable Folder. Thank you for all the advices.

  • Check out this : http://stackoverflow.com/questions/24709929/share-image-is-not-working-via-action-send/24710176#24710176 – Haresh Chhelana Jul 12 '14 at 13:01
  • Hi, I tried with your attempt but it doesn't works. When I clicked on FB Icon, I can only post something on my FB wall, without posting the image. I wrote File myFile = new File(Environment.getExternalStorageDirectory()+"/ic_launcher.png"); - I tried to post launcher icon to test it. – Lordiron Jul 12 '14 at 15:59

2 Answers2

0

first store image in sdcard then share image on facebook

File filePath = new File(Environment
                    .getExternalStorageDirectory(),
                    "/foldername/imagename.jpg");
            // share("facebook", filePath.toString());
            System.out.println(filePath);
            List<Intent> targetedShareIntents = new ArrayList<Intent>();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/jpeg");
            List<ResolveInfo> resInfo = getActivity().getPackageManager()
                    .queryIntentActivities(share, 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    Intent targetedShare = new Intent(
                            android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/jpeg"); // put here your
                                                            // mime
                    // type
                    if (info.activityInfo.packageName.toLowerCase()
                            .contains("facebook")
                            || info.activityInfo.name.toLowerCase()
                                    .contains("facebook")) {
                        targetedShare.putExtra(Intent.EXTRA_SUBJECT,
                                "Sample Photo");
                        targetedShare.putExtra(Intent.EXTRA_TEXT,
                                "This photo is created by App Name");
                        targetedShare.putExtra(Intent.EXTRA_STREAM,
                                Uri.fromFile(filePath));
                        targetedShare
                                .setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }
                Intent chooserIntent = Intent.createChooser(
                        targetedShareIntents.remove(0),
                        "Select app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetedShareIntents.toArray(new Parcelable[] {}));
                startActivity(chooserIntent);
            }
Rakesh Rangani
  • 1,039
  • 10
  • 13
  • It doesn't works. There is the similar problem. On button click I can write on FB wall but I can't share the image or the text. – Lordiron Jul 13 '14 at 13:43
0

It depends upon Facebook app whether they are accepting text or not via intent,I know they accept images and bitmap files but for text they don't accept it.I've already tried this earlier in one of my own project but couldn't supply text via intent.

The Facebook application does not handle either the EXTRA_SUBJECT or EXTRA_TEXT fields.

I have already answer this question here.May be you can follow this link in case you need reference.

Community
  • 1
  • 1
Pankaj
  • 2,115
  • 2
  • 19
  • 39