fixed rare crash on jolla devices
This commit is contained in:
parent
dac8ed6058
commit
8dc17a96ba
|
@ -3,8 +3,6 @@ package eu.siacs.conversations.utils;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.CursorLoader;
|
import android.content.CursorLoader;
|
||||||
import android.content.Loader;
|
|
||||||
import android.content.Loader.OnLoadCompleteListener;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -41,37 +39,23 @@ public class PhoneHelper {
|
||||||
CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
|
CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
|
||||||
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
|
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
|
||||||
null);
|
null);
|
||||||
mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
|
mCursorLoader.registerListener(0, (arg0, c) -> {
|
||||||
|
if (c != null) {
|
||||||
@Override
|
while (c.moveToNext()) {
|
||||||
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
|
|
||||||
if (cursor != null) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
Bundle contact = new Bundle();
|
Bundle contact = new Bundle();
|
||||||
contact.putInt("phoneid", cursor.getInt(cursor
|
contact.putInt("phoneid", c.getInt(c.getColumnIndex(ContactsContract.Data._ID)));
|
||||||
.getColumnIndex(ContactsContract.Data._ID)));
|
contact.putString("displayname", c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
|
||||||
contact.putString(
|
contact.putString("photouri", c.getString(c.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
|
||||||
"displayname",
|
contact.putString("lookup", c.getString(c.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
|
||||||
cursor.getString(cursor
|
contact.putString("jid", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
|
||||||
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
|
|
||||||
contact.putString("photouri", cursor.getString(cursor
|
|
||||||
.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
|
|
||||||
contact.putString("lookup", cursor.getString(cursor
|
|
||||||
.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
|
|
||||||
|
|
||||||
contact.putString(
|
|
||||||
"jid",
|
|
||||||
cursor.getString(cursor
|
|
||||||
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
|
|
||||||
phoneContacts.add(contact);
|
phoneContacts.add(contact);
|
||||||
}
|
}
|
||||||
cursor.close();
|
c.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onPhoneContactsLoaded(phoneContacts);
|
listener.onPhoneContactsLoaded(phoneContacts);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
mCursorLoader.startLoading();
|
mCursorLoader.startLoading();
|
||||||
|
@ -90,7 +74,7 @@ public class PhoneHelper {
|
||||||
final Cursor cursor;
|
final Cursor cursor;
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
|
cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
|
||||||
} catch (SecurityException e) {
|
} catch (Throwable e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
|
|
Loading…
Reference in a new issue