Question

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.

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

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

Was it helpful?

Solution

     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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top