Friday, June 7, 2013

Open Android market (Google Play Store) using Intent

To open google play store (Android market) using intent, just use the code snippet

String appName = "";  
Uri uri = Uri.parse("market://details?id=" + appName);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (isAvaialable(intent, mContext)) {
} else {
Uri uri = Uri.parse(""+appName);

public static boolean isAvailable(Context ctx, Intent intent) {
   final PackageManager mgr = ctx.getPackageManager();
   List list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
   return list.size() > 0;
isAvailable() is an utility method that I got from

Uniquely Identify a device in Android

For many of the application we may require to uniquely Identify android device. The best way to get the unique device Id is through Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); according to the "android developers blog".

Wednesday, May 22, 2013

After updating to ADT 22, no more files

I recently came across this problem that after updating the ADT to 22, none of my apps are building. Android can't create the file. The solution for this is, open "Android SDK Manager". Download "Android SDK build tools". Then for safety, restart your eclipse. That's it. Back to normal. All apps start building.

Wednesday, April 3, 2013

Dropbox client for Android

In one of my projects, I need to create a client in Android for Dropbox. So I like to share my experience in creating the Dropbox client. Dropbox has an Android SDK. So developers can just call the API and can use. When connecting the app with any cloud say, the authentication part is the tricky and some what complicated one. Once app establishes a connection to the cloud, then getting resources (say, files) is just a cakewalk. First I will just list down the steps for creating the dropbox client in Android.

1. First create an account in "Dropbox"

2. Then in developers page, go to the tab "My Apps". Click on the "Create an App". A dialog appears, there we specify our App name as well as the access level, either "full access" or "app folder" (means only to a specific folder in your account). We can select any one according to our choice.

3. After creating the app in dropbox, we will get the "App Key" & "App Secret". We need to use this "App Key" & "App Secret" in our application for authenticating our app with Dropbox cloud.

4. Open eclipse, create an Android app with application name same as what we provided in Dropbox page.

5. In the manifest file of the app, we need to put
 android:name="" android:launchMode="singleTask"   
      <!-- Change this to be db- followed by our app key -->  
       <data android:scheme="db-our app key" />  
       <action android:name="android.intent.action.VIEW" />          
       <category android:name="android.intent.category.BROWSABLE"/>  
       <category android:name="android.intent.category.DEFAULT" />   
This is for authenticating our app. For authenticating app will open browser with Dropbox login page, there we need to enter our Dropbox username & password. Dropbox will also ask for accessing Dropbox resources with this app. If we allow then only the android app can access Dropbox resources.

5. After allowing our app to access Dropbox resources, control will return to the application. App will return to the activtiy where it is called for authhentication. In that Activtiy in onRresume(), developer need to check whether the authentication with Dropbox is successful. If successful, app can take the desired action. Here I am just displaying all the resources in the account.

6. So app moves to the next activity named "ListDropboxActivity", where app will fetch all resources from the Dropbox and display the names of the resources as a listView. On Clicking on the resources names, app will open the resources, whether, it is a text file(.txt), or some images like .jpg, .png etc. This is all about the Dropbox client app.

You can get the full source code from here