Multiple Android permissions

288 views
Skip to first unread message

Dmitry Trunikov

unread,
Dec 6, 2013, 3:41:53 AM12/6/13
to codenameone...@googlegroups.com
Hi ALL :)

How can I specify several permissions for Android?
My application required in following permissions:
  • READ_PHONE_STATE
  • ACCESS_WIFI_STATE
  • READ_CONTACTS
  • READ_SMS
  • READ_CALENDAR
I tried several methods to specify these permissions for the build server:
  1. In a tab "Project/Properties/Build Hints" I added property android.xpermissions with value (as single line)

    <uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-permission android\:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.READ_CONTACTS" /><uses-permission android:name="android.permission.READ_SMS" /><uses-permission android:name="android.permission.READ_CALENDAR" />

    For some reason this property was not saved. When I reopened the tab "Build Hints" I did not see this property. So I applied second method (see below).
  2. In a file codenameone_settings.properties I added following line: 

    android.xpermissions=<uses-permission android\:name\="android.permission.READ_PHONE_STATE" /><uses-permission android\:name\="android.permission.ACCESS_WIFI_STATE" /><uses-permission android\:name\="android.permission.READ_CONTACTS" /><uses-permission android\:name\="android.permission.READ_SMS" /><uses-permission android\:name\="android.permission.READ_CALENDAR" />

    The line persisted but I still could not saw it in the tab 
    "Build Hints".
With this settings I successfully built *.apk package. Unfortunatelly when application run it thrown an error:

java.lang.SecurityException: Permission Denial: opening provider com.android.providers.telephony.SmsProvider from ProcessRecord{bla-bla-bla} requires android.permission.READ_SMS or android.permission.WRITE_SMS.

This error looked very strange for me because code in the application before that SMS reading makes system calls which require permission READ_PHONE_STATE and they were successful so it looks like this permissions were recognized by the build server and included in the result package but permission READ_SMS was for some reason missed. So I have checked *.apk package to find out which permissions were actually included:

aapt.exe d permissions "Main-debug (7).apk"
package: bla-bla-bla
uses-permission: android.permission.INTERNET
optional-permission: android.permission.INTERNET
uses-permission: android.permission.WRITE_EXTERNAL_STORAGE
optional-permission: android.permission.WRITE_EXTERNAL_STORAGE
uses-permission: android.permission.ACCESS_FINE_LOCATION
optional-permission: android.permission.ACCESS_FINE_LOCATION
uses-permission: android.permission.ACCESS_MOCK_LOCATION
optional-permission: android.permission.ACCESS_MOCK_LOCATION
uses-permission: android.permission.ACCESS_COARSE_LOCATION
optional-permission: android.permission.ACCESS_COARSE_LOCATION
uses-permission: android.permission.READ_CONTACTS
optional-permission: android.permission.READ_CONTACTS
uses-permission: android.permission.READ_PHONE_STATE
optional-permission: android.permission.READ_PHONE_STATE

So my question is:
  • What is a correct way to specify multiple permissions for Android platform (through tab "Build Hints" or manual editing of the file codenameone_settings.properties)?
My current development environment:
  • Windows 7 version 6.1 running on amd64; Cp1251; en_US (nb)       

  • NetBeans IDE 7.4 (Build 201310111528) , Patch 1

  • Java: 1.7.0_45; Java HotSpot(TM) 64-Bit Server VM 24.45-b08

  • CodenameOnePlugin: 1.0.60

TIA,
Dmitry

Chen Fishbein

unread,
Dec 6, 2013, 7:39:27 AM12/6/13
to codenameone...@googlegroups.com
Hi,
When adding a property directly to the properties file you need to add the codename1.arg. prefix.
in your case codename1.arg.android.xpermissions= 

Although permissions are added automatically for you according to the API you are using from the CN1 API, this arg should be used only of you are using the native interface feature and accessing the android api directly.

Dmitry Trunikov

unread,
Dec 10, 2013, 9:53:43 AM12/10/13
to codenameone...@googlegroups.com
Thank you. Your answer helped me a lot.

P.S. Yes, I use native interface so have to specify permissions.
Reply all
Reply to author
Forward
0 new messages