Prevent crash

This commit is contained in:
M66B 2018-11-07 19:16:31 +00:00
parent 53abb06efa
commit 4ad1bde2e3
2 changed files with 12 additions and 7 deletions

View File

@ -296,14 +296,17 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
boolean photo = false; boolean photo = false;
if (avatars) { if (avatars) {
if (message.avatar != null) { if (message.avatar != null)
ContentResolver resolver = context.getContentResolver(); try {
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(resolver, Uri.parse(message.avatar)); ContentResolver resolver = context.getContentResolver();
if (is != null) { InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(resolver, Uri.parse(message.avatar));
photo = true; if (is != null) {
ivAvatar.setImageDrawable(Drawable.createFromStream(is, "avatar")); photo = true;
ivAvatar.setImageDrawable(Drawable.createFromStream(is, "avatar"));
}
} catch (SecurityException ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
} }
}
} }
if (!photo && identicons) { if (!photo && identicons) {
if (message.from != null && message.from.length > 0) if (message.from != null && message.from.length > 0)

View File

@ -525,6 +525,8 @@ public class ServiceSynchronize extends LifecycleService {
cursor.getLong(0) + "/photo"); cursor.getLong(0) + "/photo");
mbuilder.setLargeIcon(Icon.createWithContentUri(photo)); mbuilder.setLargeIcon(Icon.createWithContentUri(photo));
} }
} catch (SecurityException ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();