4

Can any body tell me how can i share GIF image in android programmatically like.

Actually i want to share GIF image like android share .jpg or .png images.

I search a lot of but there is no link to share GIF image,please if anybody know please tell me.

code for sharing GIF image? startActivity(Intent.createChooser(shareIntent,"Share Emoji")); is used to share data using intent with the title "Share Emoji" whenever we share jpg or png it works perfectly. But if we try to send GIF images it does not work perfectly only email way works, if we select any other app to share GIF image like WhatsApp or Shareit, it converts GIF image to simple png image..... By this code only, i am unable to share GIF image with every other apps. So please check it and give me reasonable & practical solution if this is possible

Thank you

===============================================================

this is my code which i used currently

public class SplashScreen extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_main);
    Button click = (Button) findViewById(R.id.click);
    click.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            shareGif(getResources().getResourceName(R.drawable.clark));
        }
    });
}

private void shareGif(String resourceName) {

    String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    String fileName = "sharingGif.gif";

    File sharingGifFile = new File(baseDir, fileName);

    try {
        byte[] readData = new byte[1024 * 500];
        InputStream fis = getResources().openRawResource(getResources().getIdentifier(resourceName, "drawable", getPackageName()));

        FileOutputStream fos = new FileOutputStream(sharingGifFile);
        int i = fis.read(readData);

        while (i != -1) {
            fos.write(readData, 0, i);
            i = fis.read(readData);
        }

        fos.close();
    } catch (IOException io) {
    }
    System.out.println("===sharing file=="+sharingGifFile);
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/gif");
    Uri uri = Uri.fromFile(sharingGifFile);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(shareIntent, "Share Emoji"));
}

}

Rock Star
  • 95
  • 9
  • Good question. I want to know too. But have you look this yet. http://stackoverflow.com/a/20090354/5241603t – K.Sopheak Nov 03 '16 at 08:13
  • Why would sharing a gif be different from sharing jpg or png? – greenapps Nov 03 '16 at 08:15
  • And what is 'android share'? – greenapps Nov 03 '16 at 08:16
  • @K.Sopheak i already checked that link but i didn't want only for whats App a single app sharing... i want GIF sharing like we share and send .png and .jpg images – Rock Star Nov 03 '16 at 10:59
  • @greenapps thanks to tell me my mistake i update my question. GIF image sharing always different from sharing jpg or png because GIF image have animation in objects. You can easily send a jpg or png where as a GIF image change graphical format in motion... so it's always different. – Rock Star Nov 03 '16 at 11:05
  • Your story does not make sense. If you send a gif file with an email app it will just be send. Please post an intent to send a jpg that goes ok. Also post an intent to send a gif. So show your code in your post. (not in a comment). – greenapps Nov 03 '16 at 11:14
  • @greenapps ok, according to you if it does not make sense, then tell me how can i share gif image on all apps not only on mail. Share on other apps like WhatsApp, Facebook messanger, shareit or etc. – Rock Star Nov 03 '16 at 13:14
  • I think you can share them as you did not tell what goes wrong. Or what not happens. Or what is different when you try to share a gif instead of a jpg. If you would have started your post with explaining those problems .. – greenapps Nov 03 '16 at 14:02
  • `startActivity(Intent.createChooser(shareIntent, "Share Emoji"));` So you should have told from the beginning what is different if you try it with a gif instead of a jpg. How could we possible know what you see? – greenapps Nov 03 '16 at 14:04
  • @greenapps have try the above code for sharing GIF image? startActivity(Intent.createChooser(shareIntent,"Share Emoji")); is used to share data using intent with the title "Share Emoji" whenever we share jpg or png it works perfectly. But if we try to send GIF images it does not work perfectly only email way works, if we select any other app to share GIF image like WhatsApp or Shareit, it converts GIF image to simple png image..... By this code only, i am unable to share GIF image with every other apps. So please check it and give me reasonable & practical solution if this is possible. – Rock Star Nov 04 '16 at 06:36
  • You should have told that all right from the beginning of course. So all works and you can share a gif image. Only it is converted to png. I already asked what was different in my first comment. And only now you tell. My god what a time loss. Please put all info of your last comment at the start of your post. – greenapps Nov 04 '16 at 07:52
  • And yes as soon as you posted your code i tried it with "image/gif" and "image/*". With the latter the user could choose one app more. But of course after that some apps could not handle a gif. – greenapps Nov 04 '16 at 07:53
  • Some apps cannot handle gifs. Has nothing to do with sharing. – greenapps Nov 04 '16 at 07:56
  • That some apps (which ones?) convert gif to png. Is smething you should have told us right away. As that is not something one expects if one hears that you cannot share a gif. – greenapps Nov 04 '16 at 07:59

0 Answers0