READ_PHONE_STATE permission for IMEI not requested automatically


(Nik Holmes) #1

Hi All:
My custom fork of Collect 1.18.1 uses the phone IMEI number - but in a fresh install, calling the PropertyManager function to obtain the IMEI number returns a null value:

String deviceID = new PropertyManager(Collect.getInstance().getApplicationContext()) .getSingularProperty(PropertyManager.withUri(PropertyManager.PROPMGR_DEVICE_ID));

This appears to be because in Settings->Apps, the Permissions screen for Collect, the Telephone permission is not enabled. And if I enable it and rerun the app, I can then obtain the IMEI number using the same function call as above.
I note that when the app is installed (from an apk), the installer tells me that it doesn't need any special permissions. But the first time I run the app, I'm asked to allow it to access photos, media and files on the device - the Storage permission.
But I'm not asked about the Telephone permission, even though READ_PHONE_STATE is included in the Manifest file. And without the Telephone permission being enabled, the IMEI cannot be obtained.
Is there some way to make the app request the Telephone permission when first run, just as it currently requests the Storage permission?
Or if not, is there some way to check the permission before executing the function call, and request and implement authorisation from the user to allow the Telephone permission?
Thanks for any help!
Nik


(Nik Holmes) #2

Update - I have now worked out how to make the app request the relevant permission, and obtain the IMEI number if that permission is granted by the user. If anyone else is interested in enabling Connect to obtain the IMEI number to identify a device (eg for passing to a server to obtain a customised form list), please let me know and I'll be happy to share.
Nik