Wednesday, March 24, 2010

Custom Buttons on Android

The default buttons are a kind of ugly when you change the background of an activity. In some scenarios, you will be forced to change the way your Buttons look. To achieve this, you need not create your own custom Button class. The Android framework provides ways to achieve this with minimum effort.


Let's say we have a Button in a simple layout for which we need to do this. Here is a simple layout with just a button.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/click"
    android:background="@drawable/custom_button"
    />
</LinearLayout>
Note the android:background attribute on the Button. This refers to a drawable which is an xml in your drawable folder which will determine the different states of your button, namely,
1. default
2. pressed
3. focussed

This is the code for custom_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/focussed" />
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/focussedandpressed" />
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pressed" />
    <item android:drawable="@drawable/default" />
</selector>

For this selector tag, note all the drawable attributes. You will have different png images for each of the states which you would put in your drawable folder.

Now you have your own custom button with customized look and feel.

Thursday, March 11, 2010

Youtube/Market Intent for Search in Android

Here is a trick that would help other applications that need to open search results for videos based on a particular keyword.

You need to create an implicit Intent and trigger it. Here is a snippet of code that works.

For Youtube
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Here, "Android" is the keyword. Now, the Youtube app will show you videos with the keyword "Android"

For Market
Similarly, by changing only the package name, you can bring up search results with the Android Market app as well.

Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.android.vending");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

For Contacts
The package name for the Contacts app is "com.google.contacts".

You just need the package name of the target app if you don't want the Resolver activity to show up. This might work for other google apps as well. I haven't checked though.

Friday, February 26, 2010

Sign your Android applications for release

The process of application signing can be very confusing for new developers. But, once you have done it 2-3 times, it will be more like a chore for you after that. It's not very complicated at all. So, here are the steps that you need to follow.

Note: If you already have a self-signed certificate/keystore, skip to step 2(b):

Step 1: Right click on the Android project. From the context menu, select, Android Tools -> Export Signed application package. In the dialog that will open, you will see the name of your project. If you have selected the wrong project, here is a chance to correct yourself. Click on "Next".

 

Step 2:  The next screen is the most complicated screen that you will get in this process. Here, you can have two situations.

a. If you don't have a keystore already, you will need to create one first. Once created, you should preserve this keystore somewhere, safely, so that you don't accidentally delete it. You will need this keystore everytime you want to sign and update your application to the Android Market. Please, please, please, DO NOT LOSE THIS KEYSTORE.

                                       

Since, we are creating a new keystore this time, select the second radio, and browse to a location where you want you new keystore to be saved. Enter and confirm a password. Remember this password. Click on "Next".



Enter all the fields in this screen and press enter. Now your keystore will be created. Please rememeber all your passwords. Else, this keystore will be useless for you later.For simplicity, keep both the passwords same.



On this screen, specify a name and location of the apk and click on "Finish". Your signed application package will be created for you in the location you have mentioned here. You can now take this apk and directly upload it to the Android market, or put it on your phone.
b. When you already have a kestore, it's more easier to sign your application. On the second screen, select, "Use existing keystore". Enter the location of the keystore and password. Click on "Next". On the next screen, select you alias from the drop down, enter the alias password, click on "Next". On the next screen, specify a name and location where you want the apk to be created and click "Finish". You are done now.



Isn't it simple? Just one point to note: If you are using an old ADT version, this option of signing your apps from eclipse might now be there. In such a case, you will have to do it through command line. You can find many tutorials on how to achieve that.


Thanks,
Kumar


 

Tuesday, February 2, 2010

Market your apps aggresively

You have created a cool app, and have also updated it unto the Android Market. Great!!!! So, do you sit idle and wait for people to buy your app? Is your work done? A big "NO".

The Android Market has around 20000 apps today. And new apps are pouring in daily in large numbers. How do you tell people/users, "Hey, people, here is a cool app that you should check out"? From among these 20000 apps, people will never bother to enter your app's name in the search box. They just don't have the time.

So, how do you go about and spread the word about your app? Well, here are some tips.

1. Create a website for your app and update it regularly.
2. Create a blog for your app and provide as much information as you want about upcoming features, bugs and maybe tutorials.
3. Use twitter to reach to your friends.
4. Facebook also is quite a good medium through which you can broadcast your message on everybody's walls.
5. Create a forum for your app where people can come in and enter their issues/experiences.
6. Request some Android app websites to publish a review for your app.
7. Submit links to your website/blog to a few bookmarking websites, don't over-do it though.
8. If you want, you can also submit to alternate websites for the Android Market for people who don't have access to the market.
9. Make sure that your app has an apt description about what it does when you upload it to the market.
10. Ask for feedback from people who use your application regularly.

Friday, November 6, 2009

Market on Emulator

So, finally, we have Android Market on our emulators. Now, since it is possible, a developer can create any number of emulators with the android market on it, and login to different google accounts, and try to increase his app's ratings. This is actually too dangerous. Google doesn't discriminate requests from market apps on such emulators, and still accepts ratings and reviews. I don't know how Google can now stop this, since, everybody and anybody can now have access to the market place from his emulator. But, I am happy, :) Till Google takes any steps to curb this backdoor entry through the emulators, we can obviously expect some of those comments/reviews on the apps to be just spam. :( Google market has got to do something to stop this, and probably they will.