我在Cordova中为我的项目使用了一个插件,但已弃用,我需要通过我的方式获取联系人。我知道了,但是当我尝试发送联系人照片的位置时,必须显示图像的Web视图无法获取文件。我不知道该怎么办,该路径在webview中可见?
public static List<ContactModel> getContacts(Context ctx) {
List<ContactModel> list = new ArrayList<>();
ContentResolver contentResolver = ctx.getContentResolver();
Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
if (cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor cursorInfo = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null);
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(id));
try {
ContactModel contact = new ContactModel();
contact.id = id;
contact.displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.PHOTO_URI, ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI};
Cursor cur = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone._ID + " = ?", new String[]{id}, null);
String imageUri = null;
String thumbnailUri = null;
while (cur.moveToNext()) {
imageUri = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
thumbnailUri = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI));
}
String uri = thumbnailUri != null ? thumbnailUri : imageUri;
if (uri != null) {
**??????**
}
if (cursorInfo != null) {
while (cursorInfo.moveToNext()) {
String contactType = "";
final int labelType = cursorInfo.getInt(cursorInfo.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
if (labelType == ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM) {
contactType = cursorInfo.getString(cursorInfo.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL));
} else {
contactType = (String) ContactsContract.CommonDataKinds.Phone.getTypeLabel(ctx.getResources(), labelType, "");
}
HashMap<String, String> item = new HashMap<>();
item.put("type", contactType);
item.put("value", cursorInfo.getString(cursorInfo.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
contact.phoneNumbers.add(item);
}
}
Cursor cursorInfoEmails = contentResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);
if (cursorInfoEmails != null) {
while (cursorInfoEmails.moveToNext()) {
String emailType = "";
final int labelEmailType = cursorInfoEmails.getInt(cursorInfoEmails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
if (labelEmailType == ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM) {
emailType = cursorInfoEmails.getString(cursorInfoEmails.getColumnIndex(ContactsContract.CommonDataKinds.Email.LABEL));
} else {
emailType = (String) ContactsContract.CommonDataKinds.Email.getTypeLabel(ctx.getResources(), labelEmailType, "");
}
HashMap<String, String> item = new HashMap<>();
item.put("type", emailType);
item.put("value", cursorInfoEmails.getString(cursorInfoEmails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
contact.emails.add(item);
}
}
list.add(contact);
cursorInfo.close();
cursorInfoEmails.close();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
cursor.close();
}
return list;
}
该路径似乎未完成或其他原因。我看不到带有uri的网络视图中的照片。
我该怎么办?谢谢