Sunday, 30 January 2011

The Android Manifest file

So, time for the first hint when writing your android app using the android sdk. Today we'll talk about the AndroidManifest.xml file. You see, every app must contain an AndroidManifest.xml file in its root directory. Fortunately for you an android project is always born with this file and most often you don't have to check it. In eclipse we find it here under the project OB:

When should you care about the manifest file?

  1. When your app need to utilize an internet connection
  2. If your app closes unexpectedly during startup and you don't see any other errors in your code (AND you've spend hours of debugging hehe)

Lets take a look at the manifest file for the OB-app'en app:

<?xml version="1.0" encoding="ISO-8859-1"?> <manifest xmlns:android="" package="com.bengaard" android:versionCode="3" android:versionName="2.0"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.SET_ORIENTATION"></uses-permission> <uses-permission android:name="android.permission.ACCOUNT_MANAGER"></uses-permission> <uses-permission android:name="android.permission.MANAGE_ACCOUNT"></uses-permission> <uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission> <uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission> <uses-sdk android:minSdkVersion="3"></uses-sdk> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".OB" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

Now, the segments that you need to pay attention to is line 4 about the internet permission. If your app uses an internet connection in any way your manifest file needs to have this permission. Otherwise it just can't use a connection and nothing will happen with your app, no error, no nothing!

Also, while developing the app it would shut down numerous times unexpectedly. I found out that the reason might be that permissions were missing from the manifest file. So I wrote some more permissions found on just to be sure and that seemed to help avoid the app to shut down all the time.

When publishing your app to market notice that your manifest file has to have a package name, versionCode and versionName included. If you intend to publish your app as an update to a previous app, you need to use the same package name, a different versionCode while the versionName can be whatever you find cool. Of course, notice that if you write unnecessary permission statements your app might ask for more rights from the user than needed, which isn't a good thing. The android:minSdkVersion="3" indicates that the app runs on Android versions from 1.5 and up.

No comments:

Post a Comment