2016-09-21 8 views
3

whatsappのような利用可能なアプリケーションで.gifを共有しようとしていますが、gifの有効なUriを私のdrawableリソースに入れることができません。利用可能なアプリへのインテント共有を使ってGIF画像を共有するには?

Uri path = Uri.parse("android.resource://my_package_name/" + R.drawable.gif_1); 
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("image/gif"); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, path); 

GIF共有には何の解決策はありソリューションの多くは、画像を共有する上ではありませんが、、

答えて

7

を助けてください、私は私がちょうど拡張子.GIFのファイルを作成、GIFについては 、私の答えを見つけて、それが働きました私のために:)

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) { 
    } 
    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")); 
+0

GIFが、サーバー上にある場合はどう? –

+0

@ButaniVijay:ローカルでGIFをダウンロードしてから、同じコードで共有してください:) –

+0

よくできました。私の日を保存しました:) –

0
if you want to take image from internal storage. 

//this is method having internal storage path. 
private String getFilePath2() { 
    String root = Environment.getExternalStorageDirectory().toString(); 
    File myDir = new File(root + "/Gifs temp/"); 
    if (!myDir.exists()) 
     myDir.mkdirs(); 
    String fname = "temp_gif"; 
    SimpleDateFormat timeStampFormat = new SimpleDateFormat(
      "yyyyMMdd_HHmmss"); 
    Date myDate = new Date(); 
    String filename = timeStampFormat.format(myDate); 
    File file = new File(myDir, fname + "_" + filename + ".gif"); 
    if (file.exists()) { 
     file.delete(); 
    } 
    String str = file.getAbsolutePath(); 
    return str; 
} 




// Then take image from internal storage into the string. 
    String st = getFilePath2(); 




//And share this by this intent 
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")); 
関連する問題