Posts Tagged ‘Mobile Apps’
06
Sep

After having invested your time and efforts in developing the most creative Android application, you surely want to make it available to a larger audience. Go ahead and read this blog to find information on How to sign your Android applications and publish them to the market.

In this blog post, I am going to talk about the very basic steps that are mandatory to get application published in to Android Market. Android Market https://market.android.com is a store developed by Google for Android devices, it allows users to download published apps of different developers.

Follow the below procedure to generate a suitable .apk file for Android market.

1. Specify Version

To define the version information for application, set following attributes in the application’s manifest file:

android:versionCode - An integer value that represents the version of the application code

android:versionName – A string value that represents the release version of the application code

Versioning is required for following reasons:

  1. To check compatibility and dependency issues between applications.
  2. While Publishing and Upgrading the application to Android market
  3. It is also used in the Android Market to automatically offer application upgrades to users.

Here’s an example manifest file that shows the android:versionCode and android:versionName attributes in the <manifest> element.

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package.name"
android:versionCode="2"
android:versionName="1.1"&gt;
&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
...
&lt;/application&gt;
&lt;/manifest&gt;

2. Signing of Application

Google expects a Signed copy of the application in order to verify the developer account. The Android system will not install or run an application that is not signed. In preparation of signing the application, you must first ensure that you have a suitable private key, if you don’t have any private key then generate it with following 2 methods.

A. Using Command line tools

B. Using Eclipse ADT

A. Using Command line tools

Following are the 4 processes to generate published .apk file.

a. Obtain a suitable private key

Use following command to generate a private key:

$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Command line attributes:

  • -v = Verbose mode
  • my-release-key.keystore = generated key file
  • alias_name = alias name for application
  • validity = expiry time here is 10000

The above command generates the keystore as a file called my-release-key.keystore. The keystore and key are protected by the passwords you entered. The keystore is valid for 10000 days.

b. Compile the application in release mode

To export an unsigned .apk from Eclipse follows th steps:

  1. Right-click the project in the Package Explorer
  2. Select Android Tools > Export Unsigned Application Package.
  3. Then specify the file location for the unsigned .apk.

c. Sign your application with your private key

When application package is ready to be signed, then you can sign it by using the Jarsigner tool.

$ jarsigner -verbose -keystore my-release-key.keystore my_application.apk alias_name

Command line attributes:

  • -verbose = Verbose mode
  • my-release-key.keystore = generated key file.
  • alias_name = alias name for application
  • my_application.apk = unsigned application

While running the above command, Jarsigner prompts you to provide passwords for the keystore and key. It then signed the .apk file. Use following command to verify that your .apk is signed:

$ jarsigner -verify my_signed.apk

If the .apk is signed properly, Jarsigner prints “jar verified”.

d. Align the final APK package

Once you have signed the .apk with your private key, run zipalign on the file.The zipalign tool is available inside the Android SDK, tools/ directory folder. Follow the command to align your .apk file:

$ zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk

The input .apk must be signed with your private key before you optimize the package with zipalign

B. Using Eclipse ADT

Follow the steps to create a signed and aligned .apk by Eclipse ADT:

  1. Select the project in the Package and select File > Export.
  2. Open the Android folder, select Export Android Application, and click Next.
  3. The wizard now guide you the process of signing your application, including steps for selecting the private key or creating a new keystore and private key.
  4. Complete the Export Wizard and your application will be compiled, signed, aligned, and ready for distribution.

3. Preparing to Publish: A Checklist

Following checklist is useful while publishing android application to market.

  1. Complete your application testing extensively on an actual device
  2. Consider adding licensing support
  3. Specify an icon and label in the application’s manifest, you define the attributes android:icon and android:label in the <application> element of the manifest.
  4. Turn off logging and debugging and clean up data/files
  5. Remove the android:debuggable=”true” attribute from the <application> element of the manifest.
  6. Specifying an appropriate value for both the android:versionCode and android:versionName attributes of the <manifest> element in the application’s manifest file.
  7. Generate a private key by keytool utility and compile it with application by using release mode.
  8. In <manifest> file check that the proper permissions are used, so that user can grant permissions when application is installed in device.

For example:

<pre>&lt;uses-permission android:name="android.permission.CAMERA"&gt;&lt;/uses-permission&gt;
&lt;uses-permission android:name="android.permission.READ_PHONE_STATE"&gt;&lt;/uses-permission&gt;
&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&gt;&lt;/uses-permission&gt;
&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;</pre>

9. For supporting maximum screen sizes of devices used by customers, following attribute must be added in the Manifest file.

With these steps and procedures you are quite set to upload and disclose your Android application to the world .Some attractive screenshots along with a perfect description should get you going. So keep developing your applications with interesting UI and continue adding more innovative apps to the market and your portfolio. And if you encounter issues do write us back here and we shall surely reply.


Suresh Rapakala– Sr. Member at Xoriant QA Center of Excellence

, , , , ,

29
Aug

In the current scenario in the mobile space, there are a lot of discussions revolving around Android and its advantages and then there are those who just cannot avoid the constant comparison with the iPhone. Keeping up with the theme, now here is something that is definitely an edge for android and sure to make the iPhone users sit up and take notice. If you still haven’t guessed it, let me tell you, what  I am referring here  is the feature called widgets. For those of you who haven’t heard of widgets, this blog will give you all what you need to know.

What are Widgets?

Well, basically they are simple miniature applications/app views that can be embedded in other applications for e.g. Home screen.. I am quite sure you must be hooked up to Facebook, so say you could have a miniature view on the home screen, that allows you to post on to your wall and then constantly update you with recent likes or comments and status updates in a small scrollable view. Well this is not just a possible concept, it exists. This is exactly what a widget is. Likewise widgets exist for a variety of applications like stock market, audio manager, battery manager etc. Everything is on the home screen and you don’t even have to launch the application. The best part about a widget is, it can update itself constantly if required without you having to refresh your screen. That’s precisely as easy as it gets!!!

Now have a look at the demo snaps and then let’s get on with creating these widgets. It’s really very simple. What we are going to do is create a simple digital clock. So let’s begin!!!

Now follow these steps and you will be on your way to creating your very own widgets for the Android Application.

Step 1: Modify Android Manifest File For the Application:

What we are essentially doing here is specifying the broadcast receiver that will process the app widget updates. The meta-data tag is used to inform android about the widget provider. In this case it is located in res/xml/widget.xml. The activity tag is used to declare the activity and the event that launches it.

Have a look at the code snippet below:

<application android:icon="@drawable/icon"
                 android:label="@string/app_name"
                 android:theme="@android:style/Theme.Translucent">

		<receiver android:name=".Widget" android:label="Custom Digital Clock">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" />
        </receiver>

        <activity android:name=".info">
        	<intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.INFO" />
            </intent-filter>
        </activity>

    </application>

Step 2: Create Widget Provider xml file as specified in the manifest:

Following  is the definition of the widget. It has only one element i.e. appwidget-provider which takes attributes specifying minimum width, height, the update frequency and the initial layout or design for the widget. Now that was simple wasn’t it!!!

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dip"
android:minHeight="72dip"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget"/>


Step 3: Create Layout for the Widget(widget.xml)

Now this step is pretty self explanatory. You simply have to create layout to represent the widget. Yet the Code sample is available as always for your reference.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/Widget"
 	android:layout_width="wrap_content"
	 android:layout_height="wrap_content"
 	xmlns:android="http://schemas.android.com/apk/res/android">

 <TextView android:textColor="@android:color/primary_text_dark"
	android:padding="10dip"
	android:textSize="35dip"
	android:layout_width="wrap_content"
	android:text="12.30.35 PM"
	android:layout_gravity="center_horizontal"
	android:typeface="monospace"
	android:textStyle="bold"
	android:layout_marginRight="3dip"
	android:background="@null"
	android:layout_marginBottom="3dip"
	android:layout_marginLeft="3dip"
	android:id="@+id/widget_textview"
	android:layout_height="wrap_content"
	android:layout_marginTop="3dip"/>

</RelativeLayout>

Step 4: Create Widget Provider Class

Don’t get alarmed by the name here, it’s very simple. All you need to do is create a class that extends the AppWidgetProvider class. This is the same provider specified in the manifest file as the receiver.

The onUpdate() method needs to be overridden to include the necessary code to update time, which can be easily done using the TimerTask class in the java.util package and then it can be represented in a text view as per layout.

The onUpdate() method is called whenever an update is to be performed. Additionally pending Intents may be used to configure action to be performed on click of the widget. In this case the widget will display a simple information activity on click. Pending Intents can be given to other applications which serve as permission for the app to perform specified operation.

public class Widget extends AppWidgetProvider
{
    private Handler mHandler  = new Handler();
    RemoteViews views;
	AppWidgetManager appWidgetManager;
	ComponentName currentWidget;
	Context context;
	DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT,Locale.getDefault());

	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
	{

		//Update Widget Using a a runnable and a handler to manage it.
		.
		// some code here.
		.
		mHandler.removeCallbacks(mUpdateTask);
       		mHandler.postDelayed(mUpdateTask, 100);

	} 

	final Runnable mUpdateTask = new Runnable()
	{
	   public void run()
	   {
		   Intent informationIntent = new Intent(context,info.class);
	       PendingIntent infoPendingIntent = PendingIntent.getActivity(context, 0, informationIntent, 0);
	       views.setOnClickPendingIntent(R.id.Widget, infoPendingIntent);
		   views.setTextViewText(R.id.widget_textview,format.format(new Date()));
		   appWidgetManager.updateAppWidget(currentWidget, views);
		   mHandler.postDelayed(mUpdateTask, 1000);

	   }
	};

Step 5: Create Information activity and xml file

This is a simple activity with a text view that is used to display some information on click of the widget. Creating a layout may be a piece of cake for you by now but the sample is there for your reference as always.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
			    android:layout_width="fill_parent"
			    android:layout_height="fill_parent"
			    android:background ="@android:color/white"
			    android:scrollbars="vertical">

	<TextView android:layout_width="fill_parent"
			  android:layout_margin="3dip"
			  android:textColor="@android:color/black"
			  android:layout_height="wrap_content"
			  android:text="@string/information" />

</RelativeLayout>

So here we go, with the help of a few simple steps, we have created our very own widget. Wasn’t that straightforward? I am sure you would be amused at the simplicity of the thing and yet its elegant beauty which is there for all to see.

As with everything, along with a dozen of advantages there are a few downsides to it , else how would we improvise? So a few things that you must keep in mind while you are involved in creating widgets are:

  • They can consume a lot of resources, battery life so you need to regularly kill open unused apps.
  • They take some real estate on screen, so you need alternate screens and launchers for some extra space.

So keep these in mind while making and embedding widgets on your home screen and you should have absolutely no problem. If you still get stuck while making your widget you can always use the entire source which is available for download or leave a comment and I would be pleased to answer it.

Vinay Ramkrishnan
Vinay Ramkrishnan– Team Member – Mobile CoE

, , , ,