I wrote a simple java function in Android Studio that sticks together a contact list into a string. Data is stored in xml. The function itself works fine. But when I try to call it in Qt via QAndroidJniObject , it gives errors. If you remove all the code from the function and leave one return , then the value will be transferred ... Please help to extend this line in C ++

 public String getcontactlist() { ActivityCompat.requestPermissions(this, new String[ {Manifest.permission.READ_CONTACTS}, 1); //Запрос прав на получение контактов String fetch = "<root>"; //Создание строки и корневого элемента Cursor phones = 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; //Возвращаю значение } 

Besides the function itself, I send the source of the project to Qt. Please help get the contact list https://drive.google.com/open?id=0B434-oBPl5BmTV9vbFNHa0xGamc

The call is made through the C ++ slot of the BackEnd class. The java function itself is located in android / src / com / example / contacts / fetch / in the FetchClass.java file and has the header getContacts

  • you can get a list of contacts without java - stackoverflow.com - Qodirbek Makharov
  • So QtMobility does not have Android support, then jni should be used here ... Moreover, Qt Mobility support is no longer maintained. On the official Qt documentation page there is not a word about contacts ... doc.qt.io/qt-5/mobiledevelopment.html - Tripoli Peter

1 answer 1

All written. Here is a repo with an example of calling code on java. It will return the string with the contacts in xml. After parsing in qml and ready https://github.com/tripolskypetr/qmlcontactlist