Here is a method that receives the lines and makes the file of this photo and deletes the file at the end of the process. use it as follows: loadContactPhotoThumbnail ("content: //com.android.contacts/contacts/550/photo"); . I took most of the code from here
private String loadContactPhotoThumbnail(String photoData) {
AssetFileDescriptor afd = null;
FileOutputStream outputStream = null;
InputStream inputStream = null;
try {
Uri thumbUri;
if (Build.VERSION.SDK_INT
>=
Build.VERSION_CODES.HONEYCOMB) {
thumbUri = Uri.parse(photoData);
} else {
final Uri contactUri = Uri.withAppendedPath(
Contacts.CONTENT_URI, photoData);
thumbUri =
Uri.withAppendedPath(
contactUri, Photo.CONTENT_DIRECTORY);
}
afd = activity.getContentResolver().
openAssetFileDescriptor(thumbUri, "r");
FileDescriptor fdd = afd.getFileDescriptor();
inputStream = new FileInputStream(fdd);
File file = File.createTempFile("PhoneContactProvider", "tmp");
file.deleteOnExit();
outputStream = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
inputStream.close();
outputStream.close();
return "file://" + file.getAbsolutePath();
} catch (Exception e) {
App.logger().e(this.getClass().getSimpleName(), e.getMessage());
}
finally {
if (afd != null) {
try {
afd.close();
} catch (IOException e) {}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {}
}
}
return null;
}
: 4.1.2 4.0.3