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,36 +39,22 @@ 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) {
|
Bundle contact = new Bundle();
|
||||||
if (cursor != null) {
|
contact.putInt("phoneid", c.getInt(c.getColumnIndex(ContactsContract.Data._ID)));
|
||||||
while (cursor.moveToNext()) {
|
contact.putString("displayname", c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
|
||||||
Bundle contact = new Bundle();
|
contact.putString("photouri", c.getString(c.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
|
||||||
contact.putInt("phoneid", cursor.getInt(cursor
|
contact.putString("lookup", c.getString(c.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
|
||||||
.getColumnIndex(ContactsContract.Data._ID)));
|
contact.putString("jid", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
|
||||||
contact.putString(
|
phoneContacts.add(contact);
|
||||||
"displayname",
|
|
||||||
cursor.getString(cursor
|
|
||||||
.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);
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
}
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onPhoneContactsLoaded(phoneContacts);
|
listener.onPhoneContactsLoaded(phoneContacts);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
@ -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 New Issue