如何将图像发送到图库设置壁纸?

时间:2014-01-25 07:45:13

标签: android android-intent android-gallery

我试图使用默认的图库应用程序集合设置为壁纸选项,我不知道如何使用intent将图像发送到图库。我正在附上fb app样本的外观。

wallpaper1 wallpaper2

 String root = Environment.getExternalStorageDirectory().toString();
                    new File(root + "/"+Constants1.APPNAME).mkdirs();


                    File fileForImage = new File(root + "/"+Constants1.APPNAME, pos  + ".jpg");
                    if (fileForImage.exists()) fileForImage.delete(); 
                    try {
                        FileOutputStream out = new FileOutputStream(fileForImage);
                        arg0.compress(Bitmap.CompressFormat.PNG, 100, out);
                        Toast.makeText(getApplicationContext(), "Image is saved to "+Constants1.APPNAME+" folder", Toast.LENGTH_SHORT).show();
                        out.flush();
                        out.close();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Intent emailIntent = new Intent(Intent.ACTION_ATTACH);
                    emailIntent.setType("image/png");
                    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileForImage));
                    startActivityForResult(Intent.createChooser(emailIntent, pos+".jpg"),0);

问题是图像没有传递到图库..

1 个答案:

答案 0 :(得分:1)

     Intent emailIntent = new Intent(Intent.ACTION_ATTACH_DATA);
                        emailIntent.setDataAndType(Uri.fromFile(fileForImage), "image/*");
                        //emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileForImage));
                        startActivity(emailIntent);
                        Toast.makeText(getApplicationContext(), "Image is saved to "+Constants1.APPNAME+" folder", Toast.LENGTH_SHORT).show();