how to send images to gallery for setting the wallpaper?

狂风中的少年 提交于 2020-01-14 03:38:08

问题


i was trying to integrate set as wallpaper option using default gallery app, I don't know how to send the image to gallery using intent. I am attaching fb app samples how its look like.

 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);

The problem is that the image is not passing to the gallery..


回答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();


来源:https://stackoverflow.com/questions/21348052/how-to-send-images-to-gallery-for-setting-the-wallpaper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!