Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android:从drawable共享gif图像_Android - Fatal编程技术网

android:从drawable共享gif图像

android:从drawable共享gif图像,android,Android,我想把.gif从我的应用分享到facebook,gmail 您好,有没有办法共享gif图像 我在可绘图文件夹(“giphy.gif”)中有gif 下面是我尝试过的代码,但它给了我错误。(没有附加文件) 首先添加权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 工作起来很有魅力 首先添加权限 <uses-permission android:name="android.p

我想把.gif从我的应用分享到facebook,gmail

您好,有没有办法共享gif图像

我在可绘图文件夹(“giphy.gif”)中有gif

下面是我尝试过的代码,但它给了我错误。(没有附加文件)

首先添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
工作起来很有魅力

首先添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
工作起来很有魅力

try {
            CopyRAWtoSDCard(mContext,R.drawable.giphy, "giphy");
        } catch (IOException e) {
            e.printStackTrace();
        }

        File sdcard = Environment.getExternalStorageDirectory();
        File file = new File(sdcard,"/yourapp/giphy.gif");



            it.setType("image/*");
            it.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            it.putExtra(Intent.EXTRA_SUBJECT, mContext.getString(R.string.app_name));
            it.putExtra(Intent.EXTRA_TEXT, "Gif attached");
            it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Intent in = Intent.createChooser(it,"Share");
            in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(in);


private void CopyRAWtoSDCard(Context mContext,int id,String name) throws IOException {


    String path = Environment.getExternalStorageDirectory() + "/yourapp";
    File dir = new File(path);
    if (dir.mkdirs() || dir.isDirectory()) {
        try {

            InputStream in = mContext.getResources().openRawResource(id);
            FileOutputStream out = new FileOutputStream(path+ File.separator + name+".gif");
            byte[] buff = new byte[1024];
            int read = 0;
            try {
                while ((read = in.read(buff)) > 0) {
                    out.write(buff, 0, read);
                }
            } finally {
                in.close();
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}