About AIR Applications and Android Permissions

After I saw some tweets about issues related to accessing the Wi-Fi network from an AIR application running on Android I thought it would be worth writing a post about this topic.

If you have installed an Android application on your phone you know that during this process you are presented with a screen stating what permissions the application you are about to install will use: network communication, contact data, location, storage, and so on.

I think this is a good thing especially when dealing with applications from “not so trusted” sources. You have a last chance to decide if you are willing to install that app or not. Thus it is only natural Android apps built with Adobe AIR to follow the same rules. One more thing on security/permissions: I think it is a best practice, as a developer, to request the minimum permissions required for your application.

The way you set up these permissions is quite simple: you add an <android> node to your application descriptor file having the <application> node as the root (the application descriptor file is the XML file you already use for setting the different configuration options for your AIR application – application name, enabling the update framework, initial size and position, and so on). Here is an example:

Later Edit:

<android>
    <manifestAdditions>
        <manifest>
            <attribute name="android:installLocation" value="auto"/>
            <data>
            <![CDATA[
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
                <uses-permission android:name="android.permission.INTERNET"/>
                <uses-permission android:name="android.permission.WAKE_LOCK"/>
                <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
                <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
                <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
            ]]>
            </data>
        </manifest>
    </manifestAdditions>
</android>

My colleague Ashutosh Sharma kindly pointed out that this mechanism was slightly changed recently:

<android>
    <manifestAdditions>
    <![CDATA[
    <manifest android:installLocation="auto">
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        <uses-configuration android:reqFiveWayNav="true"/>
        <supports-screens android:normalScreens="true"/>
        <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>
        <application android:enabled="true">
            <activity android:excludeFromRecents="false">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <activity>
            </activity>
        </application>
    </manifest>
    ]]>
    </manifestAdditions>
</android>

In this example I added an additional setting in the form of android:installLocation=”auto” as the attribute for the <manifest> node in order to allow the user to install the application either on the internal memory or on the SD memory card. The same way you can add additional permissions supported by the Android OS.

Now, next time when you have problems accessing resources from your AIR app on Android, you should know that this is the first thing to look for.

10 thoughts on “About AIR Applications and Android Permissions

  1. Looks like all indentation was lost. Here it is again:

    <android>
         <manifestAdditions> 
              <![CDATA[
                <manifest android:installLocation=”auto”>
                      <uses-permission android:name=”android.permission.INTERNET”/>
                      <uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
                      <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
                      <uses-configuration android:reqFiveWayNav=”true”/>
                      <supports-screens android:normalScreens=”true”/>
                      <uses-feature android:required=”true” android:name=”android.hardware.touchscreen.multitouch”/>
                      <application android:enabled=”true”>
                            <activity android:excludeFromRecents=”false”>
                                  <intent-filter>
                                        <action android:name=”android.intent.action.MAIN”/>
                                        <category android:name=”android.intent.category.LAUNCHER”/>
                                  </intent-filter>
                            </activity>
                            <activity>
                            </activity>
                      </application>
                </manifest>
              ]]>
          </manifestAdditions>
    </android>

  2. Hi Mihai,

    I’m on Ubuntu and obviously don’t have access to Flash Pro or Flash Builder, so I use a 3rd-party tool to build my swf and then use the command line and the Air and Android sdk’s to build Air for Android apps. I’ve succeeded in getting a Hello World app on my emulator this way. Would I simply add this as a node to, for instance, my HelloWorld-app.xml file? And would it be at the same “node level” as, say, the id and filename nodes? Thanks!

  3. Hi Mihai,

    This is really nice! Is the also documentation from Adobe about this? Because in the pre-release docs is nothing like this. The extra options I mean.

    Hope to hear from you,

    Kind regards,
    Sidney

  4. Hi,

    whenever I add android:screenOrientation=”portrait” in the activity tag and try to install/run it in the android device, I get packaging error. But it is running without any issue in my system. Please help.

    Regards
    Preetam

  5. @Preetam

    If you to force your app to start and stay in portrait, then you have to add these tags inside the node of the application descriptor file:

    portrait
    false

  6. Hello ,

    Is the Flex mobile support following permissions

    If so let me know how to read and write the contacts using flexmobile or air
    thanks

  7. Hello ,

    Is the Flex mobile support following permissions
    >uses-permission android:name=”android.permission.READ_CONTACTS”uses-permission

    >uses-permission android:name=”android.permission.WRITE_CONTACTS”
    >uses-permission

    If so let me know how to read and write the contacts using flexmobile or air
    thanks

  8. @Naveen

    You should check the Native Extensions feature part of the upcoming AIR 3. You can extend AIR by creating native extensions that expose OS/Device APIs to AIR.

    cheers,
    Mihai

  9. You can simply copy and edit provided template in “flexsdk\templates\air” just open “descriptor-template.xml” and fill the required fields. On the end there is a necessary Android CDATA and you only need to remove comments.

  10. I am trying to embed my flex android apk into android native app,at the time of installation my native app into device it is asking for installation of flex app also, I just want to set single installation process for both. How can i do this?
    Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *