Wednesday 27 February 2013

Sunday 17 February 2013

Android Dropbox Integration

Hello Droid Guys,

Today, I am going to provide you a full tutorial of dropbox integration into your
android application with source code. Using this you can easily :
            1. upload your image in your dropbox.
            2. upload your text file and document  into your dropbox.
            3. upload your audio and video file into  your dropbox.

Also , List or fetch all your dropbox file, folder and images by your android application.

Step 1: Create an app and get the API KEY and SECRET KEY:
          a) Open this link https://www.dropbox.com/developers and logged in with your
              dropbox credential.

dropbox sync
                           



android dropbox sample


 b) After Logged in , the next page ask you for create an app

android dropbox sample

C) Insert the app name and description and provide the access as full dropbox by 
selecting the second option.
dropbox integration


d) Note your app key and secret key
dropbox integration

                                            
Step 2) Download the android  Sdk for dropbox form HERE

dropbox integration

Now all Done , import the project into your android eclipse and please remember to 
change secret key and App key with your own key.


Hope this will helps you.
Enjoy Coding :)


Saturday 16 February 2013

android.os.NetworkOnMainThreadException in android

Hello Droid Guys,

Yesterday , I found a strange issue, my application is running fine on most of
the android devices. But when I run the same application on Samsung S-3, S2,
Samsung Galaxy Duos it will be crashed and give me the error

"android.os.NetworkOnMainThreadException".


Caused by: android.os.NetworkOnMainThreadException
10-30 15:07:35.341: E/AndroidRuntime(732):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)

In my application basically I am showing a alert dialog with an logout button and on click of logout
button I am calling the service. This functionality is not working on above few device
and crashes every time on clickinng the logout button .

After spending a lot of time on it I came to know that on device api version below 9 we 
can call or write  network call in Main UI Thread but above api version 9 it gives error
android.os.NetworkOnMainThreadException. This is happening my  case.

There are Two way to fix this Issue:
    1.Instead of writing network call in Main UI Thread use Async Task.
    2.Add below code into your activity class inside onCreate() method just  after the 

      setContentView(R.layout.activity_main).
      
     if( Build.VERSION.SDK_INT >= 9){
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy); 
     }



Hoping , this will helps you.
Enjoy Coding :)
   

 

Copyright @ 2013 Android Developers Blog.