Obsolete Members for NativeUtils

The following members of QML type NativeUtils are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

Methods

Method Documentation

var getContacts(bool includeAllNumbers)

Returns a list of all contacts including name and phone number. This method is only supported on Android and iOS.

On iOS, it is required to add an NSContactsUsageDescription entry to your Project-Info.plist:

 <key>NSContactsUsageDescription</key>
 <string>App would like to read contacts from the Addressbook.</string>

On Android, it is required to add the READ_CONTACTS permission to your AndroidManifest.xml:

 <uses-permission android:name="android.permission.READ_CONTACTS"/>

Note: If your targetSdkVersion in AndroidManifest.xml is 23 or higher, it asks the user for the permission on first use. At this point, this method returns an empty list of contacts. Once the user accepted the permission, it returns the actual contacts. This method is now deprecated. You can use contacts instead. These properties update once the user accepted the permission.

The call returns a JSON array with objects containing keys name and phoneNumber:

 [
   { name: "Kate Bell", phoneNumber: "(555) 564-8582" },
   { name: "Daniel Higgins", phoneNumber: "555-478-7672" },
   ...
 ]

If you set the optional includeAllNumbers parameter to true, you get an array of all phone numbers attached to a specific contact:

 [
   { name: "Kate Bell", phoneNumbers: ["(555) 564-8582", "(555) 524-7213"] },
   { name: "Daniel Higgins", phoneNumbers: ["555-478-7672"] },
   ...
 ]

Use this example code to show all contacts with name and a single phone number:

 import VPlayApps 1.0

 App {
   Page {
     AppListView {
       anchors.fill: parent
       model: nativeUtils.getContacts()

       delegate: SimpleRow {
         text: modelData.name
         detailText: modelData.phoneNumber
       }
     }
   }
 }

Use this example code to show all contacts with name and all attached phone numbers:

 import VPlayApps 1.0

 App {
   Page {
     AppListView {
       anchors.fill: parent
       model: nativeUtils.getContacts(true) // Set to true to get all attached phone numbers

       delegate: SimpleRow {
         text: modelData.name
         detailText: modelData.phoneNumbers.join(", ") // Join all numbers into a string separated by a comma
       }
     }
   }
 }

Note: The phone numbers are returned in the format as they are stored in the address book by the user. To normalize phone numbers, you can use the country code of the device's own phone number and replace the starting 0 with the device's country code.

See also phoneNumber, getPhoneCountryIso(), storeContacts(), and contacts.


string getPhoneNumber()

Returns the mobile device's phone number, if available. It might not be available if the user is not registered to a network or if the network does not provide this information. The return value is a string containing the number, for example "+11234567", or an empty string "", if not available.

If your app or game has a functionality that needs the user's phone number and this method can not provide it, you can ask your user to enter his or her phone number using a displayTextInput().

This method is only supported on Android, as it is not possible to access the device phone number on iOS. On Android, it is required to add the READ_PHONE_STATE or READ_SMS permission to your AndroidManifest.xml:

 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Note: If your targetSdkVersion in AndroidManifest.xml is 23 or higher, it asks the user for the permission on first use. At this point, this method returns an empty string. Once the user accepted the permission, it returns the actual phone number. This method is now deprecated. You can use phoneNumber instead. That property automatically updates once the user accepted the permission.

See also phoneNumber, getPhoneCountryIso(), contacts, and storeContacts().


Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support