Monday 18 November 2013

Android Lazy Image loader Class Error | Image Loader not loading the image

Hello Friends,


One of my friend using Image Loader class to load an image from an url and displaying it
in a list view. She told me that the Image Loader is loading the image on an emulator, when
she run the app on a real device it's not loading any image.(Just showing the default image).

This problem occurs only when we didn't pass the permission in AndroidManifest.xml file.
When I saw her code I found following permission is missing..

 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


After adding this , the problem is resolved and the the app is working fine on
both emulator as well as on real device.

This issued is faced by most of the android developer , So always remember add
all permission while using lazy Image loader class.

Enjoy.... :)
Happy Coding....

Thursday 14 November 2013

Invalid android_key parameter - Facebook login | Android Facebook hash key error

Hello Droid Friends,
Today , I stuck in Facebook login Issue. I am doing facebook login in my android
application but I am getting following error:


Invalid android_key parameter. The key 26gUhN_wYCwwxenlSneyTeCY
does not match any allowed key. Configure your app key hashes at 
http://developers.facebook.com/apps/22061641443615

I followed following steps:
1. downloaded openssl from here and set it in your system environment path.
     
2. Uses following command to generate hashkey on my pc.
      keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Acer\.android\debug.keystore"
                                 | openssl sha1 -binary | openssl base64
 

3. Then I created a new Facebook app  and also added the generated hashkey.

4. I got the Facebook App Id Which I am now using in my and application.


After following all above steps , still I am facing the error "Invalid android_key
parameter" . Then I go to the facebook developer site and find few new things which
comes in Facebook SDK 3.5. And Its helps me in fixing the above "Invalid android_key
parameter" Issue. There Are Two way:

Step-1. When you get this error, check the logcat it returns you a different hashkey,
so you just need to replace the previous hashkey with this one. If you did not getting
any hashkey in logcat error then step-2 helps you.

Step-2: I think this is the best way of generating hashkey bcoz it removes the dependency
of debugkeystore.No need to copy and paste the same debugkeystore on each developer
machine.Here we generate hashkey on the basis of android application package name.
Just used following code for generating the hashkey.

try  {

      PackageInfo info = getPackageManager().
           getPackageInfo(this.getPackageName(), PackageManager.GET_SIGNATURES);

      for (Signature signature : info.signatures) {

          MessageDigest md = MessageDigest.getInstance("SHA");
          md.update(signature.toByteArray());
          Log.d("====Hash Key===",Base64.encodeToString(md.digest(), 
                   Base64.DEFA  ULT));

      }

  } catch (NameNotFoundException e) {

      e.printStackTrace();

  } catch (NoSuchAlgorithmException ex) {

      ex.printStackTrace();

  }




And use this generated hashkey.This will fixed your "Invalid android_key parameter" issue.

Enjoy :)
Happy Coding... :)


Sunday 10 November 2013

Android Home key press behavior | Activity stack confused when launching app

Hello Droid Guys
I found an strange issue with the behavior of Home key press in android.Please
check below link if you want more details about this issue.


Actually, I think this is an android bug. If an app is installed via market, market 
update, or download from browser and the user launches the app directly from the
installer (ie: when the installer completes it offers the user the options to launch(open)
and done and when use select open the app now) it is launched in such a way that 
the OS gets confused.

If, after the app is launched, the user presses the HOME key to return to the home 
screen and then tries to return to the app by selecting it from the list of applications 
(or by putting a shortcut on the home screen and then selecting the shortcut), the OS
launches the root activity of the app AGAIN, bringing the existing task to the foreground
and placing ANOTHER instance of the root activity on top of the existing activity stack.

This behavior is extremely difficult to debug and has certainly caused countless hours 
of head-scratching by developers.

Note: I too found the same issue when I install an app from my mail and directly launch
the app.Go to Activity "A" then goes to Activity "B" and then I pressed "Home button".
Then ,When I open the same app pressing the app launcher on home screen,Instead of 
taking me directly to Activity "B" where I left it last time , It loads the app from the start.



It takes lots of my time to fixed this issue but finally I did that. I found the
way to resolve this problme :) .
I Added following code in the onCreate() method of my launcher activity and then Its
works fine for me.


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);

if (!isTaskRoot()) {
           Intent intent = getIntent();
           String action = intent.getAction();
           if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null &&                           action.equals(Intent.ACTION_MAIN)) {
               finish();
               return;
           }
    }
}

Hope, my above code will save some one time.
Enjoy Coding :)

Saturday 9 November 2013

Android ListView Background Color Changes on Scrolling

Hello Friends,
This is very common issue I saw in android with Listview. In one of my app I am using a
listview for displaying the list of Items.I set the background of Listview as blue. Below is 
the Listview code which I am using.

 <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:background="#0000FF"/>


But, some times when I scroll the Listview the background color will be automatically change
to black or white. Then, I found a solution I added below line in my Listview(in xml file).

android:cacheColorHint="#00000000"
        OR
android:cacheColorHint="@android:color/transparent"


And Finally my Listview code contains following code.....

<ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:cacheColorHint="#00000000"
        android:choiceMode="singleChoice"
        android:background="#2A323D"/>

OR at java code,use below line of code

listview.setCacheColorHint(Color.TRANSPARENT);


After adding the above one line in my xml or java file , the Listview background color 
change on scrolling issue will be gone.

Hope , the above code helps some one.
Enjoy coding......




 

Copyright @ 2013 Android Developers Blog.