Qt qml显示设备联系人列表

时间:2016-12-28 08:06:52

标签: android ios qt qml contacts

我想在Qt / QML(Android / iOS)上的应用上显示设备联系人列表。是否有人在Qt / QML中实现它或者我应该在java(Android)和Objective-C(iOS)上实现它?提前致谢

1 个答案:

答案 0 :(得分:2)

你可以在github上使用我的例子, https://github.com/tripolskypetr/qmlcontactlist

package com.example.contacts.fetch; 
import android.provider.ContactsContract; 
import android.content.Context; 
import android.database.Cursor; 

public class FetchClass extends org.qtproject.qt5.android.bindings.QtActivity {
public FetchClass()
{
}
public static String getContacts(Context c) {
//ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_CONTACTS},1);
String fetch="<root>";

Cursor phones = c.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

while (phones.moveToNext()) {
    String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
    String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
    fetch+="<item><name>"+name+"</name><number>"+phoneNumber+"</number></item>";
}
fetch+="</root>";
return fetch;
} 
}