Solved issue of image not picked from Photo's App

If we select image from Google's Photos app. It wasn't getting selected due to invalid image path error. Thus it was returning null Bitmap, which is solved in this patch.
This commit is contained in:
Aniruddh Bhilvare 2017-10-17 15:07:36 +05:30 committed by Erwan Croze
parent 0e84a12140
commit cbdfebc632

View file

@ -94,6 +94,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -798,6 +799,26 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) { if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) {
try { try {
Bitmap bm = BitmapFactory.decodeFile(path); Bitmap bm = BitmapFactory.decodeFile(path);
if (bm == null && path.contains("NONE")) {
Uri uri = Uri.parse(path);
InputStream is = null;
if (uri.getAuthority() != null) {
try {
is = getActivity().getContentResolver().openInputStream(uri);
bm = BitmapFactory.decodeStream(is);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
if (bm != null) { if (bm != null) {
FileUploadPrepareTask task = new FileUploadPrepareTask(getActivity(), path, imageSize); FileUploadPrepareTask task = new FileUploadPrepareTask(getActivity(), path, imageSize);
task.execute(bm); task.execute(bm);