问题
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