0

I am working in one Application where i can share my gallery image to facebook,twitter

i have searched the some links..Where everybody mentioned as intent service..but i do not know how it will use in my application,i would really be thankful if somebody help me with complete code

            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpeg");

            share.putExtra(Intent.EXTRA_STREAM,
              Uri.parse("file:///sdcard/DCIM/Camera/myPic.jpg"));

            startActivity(Intent.createChooser(share, "Share Image"));

1 Answers1

2

Try this code:

    Button button = (Button)findViewById(R.id.facebookButton);

    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
                    String path = "path to the image";
                    Uri imageUri = Uri.parse(path);

                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                    sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
                    sharingIntent.setType("image/png");

                     startActivity(Intent.createChooser(sharingIntent , "Send image using.."));

        }
    });
edwoollard
  • 12,245
  • 6
  • 43
  • 74
Naskov
  • 4,121
  • 5
  • 38
  • 62
  • Is this automatically share the image –  Feb 11 '13 at 05:58
  • It's opening new intent but you need user interaction to continue the Share. – Naskov Feb 11 '13 at 08:42
  • could you explain it better –  Feb 11 '13 at 09:14
  • on click share button i can share images using the above coding –  Feb 11 '13 at 09:37
  • What are you asking exactly? How to use the code that I posted? What are you missing there? – Naskov Feb 11 '13 at 09:39
  • yes i need to know the full code ,,on click facebook button the image is sharing , –  Feb 11 '13 at 09:43
  • is this same for facebook and twitter –  Feb 11 '13 at 09:47
  • Yes it's the same. You only need to have installed facebook and Twitter apps on your device, and when the intent will pop up you will have all of the listed apps that are able to share that data. – Naskov Feb 11 '13 at 09:49
  • you mean i need to integrate facebook ,twitter code ..with my apps –  Feb 11 '13 at 09:54
  • one more doubt is it necessary to integrate facebook twitter with my code –  Feb 11 '13 at 09:57
  • It's not, the intent will run facebook and twitter bu default. And accept and upvote the answer if that helped you :) – Naskov Feb 11 '13 at 09:58
  • What kind of error are you getting? Can you post the stacktrace? – Naskov Feb 11 '13 at 10:36
  • Your app is independent from facebook now.. The intnet is only passing the data true the Android OS and Android OS is telling the Facebook and Twitter apps to share the content. Is your app crashing or the facebook? – Naskov Feb 11 '13 at 10:48
  • k..its fine,.can we see data in facebook..that the image is from that particular application –  Feb 11 '13 at 10:59
  • You gonna need a facebook integration for that.. That is a very complex problem.. See http://stackoverflow.com/questions/3372020/facebook-integration-in-android-application – Naskov Feb 11 '13 at 12:18