I use this code below, but it works partly - set wallpapers only on my real device api23 nexus5, in another devices in no way not setting. Also cant set wallpapers to icon of contact.
My actions:
if choosed 'Contact photo' - open the service and if choose any contact
if choosed 'Wallpaper'
Expected result: open the service and tap to set
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); // attach services
intent.addCategory(Intent.CATEGORY_DEFAULT);
file = new File(getFolderStorageDirectory(), getFileName()); // create temp file
if (isExternalStorageWritable()) { // check whether available external storage
try {
FileOutputStream out = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); // write image
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "File not saved");
}
} else {
showToast(getString(R.string.sd_card));
}
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "image/*");
intent.putExtra("mimeType", "image/*");
intent.putExtra("jpg", "image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.getAbsolutePath()));
startActivity(Intent.createChooser(intent, "Select service:"));
Why not work?
I solved this problem.
Instead
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "image/*");
use
setAs.setDataAndType(Uri.fromFile(mFile), "image/*");
and it will work.
All code:
private void setAsUseServices() {
onCreateFileListener(); // here will create file e.g. in Picture directory
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.addCategory(Intent.CATEGORY_DEFAULT);
Uri sourceUri = Uri.fromFile(mFile);
setAs.setDataAndType(sourceUri, "image/*");
setAs.putExtra("mimeType", "image/*");
setAs.putExtra("save_path", sourceUri);
startActivity(Intent.createChooser(setAs, "Select service:"));
}