Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Go Public with Your Android Application: Signing and Deployment

In order to deploy your application on Android devices (and on the Android Market), you need to sign it. Luckily, you can generate your own certificate and use it to sign your application. Find out how the process works.


advertisement
o far, you've been learning about the interesting things you can do with Android. However, if you want your application to see the light of day and run on other users' devices, you need a way to distribute your application and deploy them onto your target devices. This article will show you how to prepare your Android applications for deployment and get them onto your customers' devices.

Creating the Sample Application
A simple Android application will illustrate deployment on an Android device. So, using Eclipse, create a new Android project.

Versioning
Beginning with version 1.0 of the Android SDK, the AndroidManifesl.xml file of every Android applications include the android:versionCode and android:versionName attributes:



<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.learn2develop.MyKillerApp" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MyKillerApp" android:name ="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

The android:versionCode attribute represents the version number of your application. For every revision you make to the application, increment this value by 1 so that you can programmatically differentiate it from its previous version. This value is never used by the Android system, but it's useful as a way to obtain the version number of an application.

The android:versionName attribute contains versioning information that is visible to the users. It should contain values in the following format: <major>.<minor>.<point>.

If you are planning to publish your application on the Android Market, the AndroidManifest.xml file must have the following attributes:

  • android:versionCode
  • android:versionName
  • android:name
  • android:name
In addition, if your application needs a minimum version of the SDK, you can specify it in the AndroidManifest.xml file using the element, like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.learn2develop.MyKillerApp" android:versionCode="1" android:versionName="1.0.0"> <uses-sdk android:minSdkVersion="1" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MyKillerApp" 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>

As the current version of the SDK is 1.0, there is no necessity for you to specify the minimum version of the SDK required.

To programmatically retrieve the value of the android:versionCode attribute, use the PackageManager class' getPackageInfo() method. To see how this can be done, give an id to the <TextView> view in main.xml, like this:

<TextView android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />

In MyKillerApp.java, add the following code to retrieve the version code of the application:

Figure 1. Run the App: Displaying the application's versionCode.

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PackageManager pm = getPackageManager(); try { //---get the package info--- PackageInfo pi = pm.getPackageInfo("net.learn2develop.MyKillerApp", 0); //---display the versioncode--- TextView tv = (TextView) findViewById(R.id.textview); tv.setText("VersionCode: " +Integer.toString(pi.versionCode)); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

When you run the application, it will display the value of the android:versionCode attribute (see Figure 1).



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap