I have written my own ImageViewer and now I want to have Set as functionality like in Android native ImageViewer. I now it is possible since Facebook has it. I've attached a screenshot to make myself more clear.
P.S. I want to give a more detailed explanation of what goes wrong. After I choose "Contact icon" in the menu the list of my contacts appears. When I choose a contact the application force closes. If I choose "Home/Lock screen wallpaper" it opens my phone's gallery. Here is my code snippet:
Bitmap icon = mBitmap;
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.setType("image/jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "/my_tmp_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
setAs.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/my_tmp_file.jpg"));
startActivity(Intent.createChooser(setAs, "Set Image As"));
I have also added the consequent permissions to my manifest and I am able to write my image to the sd card of the phone.