About muthumanict

Hi am muthumani, i am working as an Android developer. Its great working with an open source product and i am here to promote it.

2014 in review

The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 3,600 times in 2014. If it were a cable car, it would take about 60 trips to carry that many people.

Click here to see the complete report.


Adding request header to cordova webview

To add headers while making request to URL through Cordova WebView following steps has to be followed:

  1. Create a HashMap and add the header parameters to this HashMap
  2. Pass the HashMap to WebView’s loadUrl function along with the URL
  3. In shouldOverrideUrlLoading method of CordovaWebViewClient or WebViewClient add the same HashMap to WebView’s loadUrl function along with the URL

Creating a HashMap:

Map<String, String> map = new HashMap<String, String>();

map.put(“header_name”, “value”);

Passing the header value while calling loadUrl:

loadUrl(url, map);

Passing the same headers in shouldOverrideUrlLoading:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url, map);
return true;

Note: The HashMap which contains the headers should be passed while calling loadUrl of WebView as well as shouldOverrideUrlLoading of WebViewClient.

Not able to generate apk

If you are not able to build your project even after downloading and installing ADT properly then you must have missed Downloading Build tools from Android SDK Manager.

Open your Android SDK Manager and look for Android SDK Build-tools 



If Android SDK Buil-tools is not installed then this is what blocking you from generating apk. Install it and it and everything should work fine.  Make sure that there is no compilation issues in your resource folder.

Possible errors while running test cases

While writing functional or unit test cases through Robotium or  InstrumentationTestCase if you get

TestCase class com.example.test.WelcomeActivityText is missing a public constructor with no parameters or a single String parameter

at run time then this must be because of your test project dint include a default constructor. That is

import com.example.WelcomeActivity;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;

public class WelcomeActivityText extends ActivityInstrumentationTestCase2<WelcomeActivity> {

    private Solo mSolo;
    public WelcomeActivityText() {
    protected void setUp() throws Exception {
        mSolo = new Solo(getInstrumentation());
    public void testWelcomeActivity(){
        assertEquals(WelcomeActivity.class, getActivity().getClass());
        mSolo.assertCurrentActivity("WelcomeActivity is not shown", WelcomeActivity.class);


If you create a default constructor like the above code you can get ride of this error.

Invalid Package: ” could not be found or has no tests”

If you get this error means then please do check you have started your test case function with test as prefix (testWelcomeActivity).

Problem While triggering Notification

To create a notification refer this link.

Mostly everything should work perfectly. Suppose if you get the bellow error

Suppressing notification from package com.example.notify by user request  then it means that notification is blocked by the Android Framework since the Show notifications check box in Application Manager is unchecked. By default this check box will be checked but there are possibilities that this may get unchecked (I have seen its getting unchecked in one Samsung Nexus S device). Just checking the check box will solve your problem. Show Notifications is available inside Setting->Application Manager ->Downloads->Your Application

Application Manager App

Application Manager App

Restructuring DatePickerDialog

If you want to restrict your user not to enter date lesser then the current date from DatePickerDialog then you can use the below code as such :

try {
            DateTime dt = new DateTime(desiredDate, DateTimeZone.UTC);

            DatePickerDialog selectDatePicker = new DatePickerDialog(this, mDateSelectedListener, dt.getYear(),
                    dt.getMonthOfYear() - 1, dt.getDayOfMonth());
            java.lang.reflect.Field mDatePickerField = selectDatePicker.getClass().getDeclaredField("mDatePicker");
            DatePicker mDatePicker = (DatePicker) mDatePickerField.get(selectDatePicker);

            mDatePicker.init(dt.getYear(), dt.getMonthOfYear() - 1, dt.getDayOfMonth(),
                    new OnDateChangedListener() {

                        public void onDateChanged(DatePicker view, int year, int monthOfYear,
                                int dayOfMonth) {

                            if (isDateAfter(view)) {
                                Calendar mCalendar = Calendar.getInstance();
                                        mCalendar.get(Calendar.DAY_OF_MONTH), this);

                        private boolean isDateAfter(DatePicker tempView) {
                            Calendar mCalendar = Calendar.getInstance();
                            Calendar tempCalendar = Calendar.getInstance();
                            tempCalendar.set(tempView.getYear(), tempView.getMonth(),
                                    tempView.getDayOfMonth(), 0, 0, 0);
                            if (tempCalendar.before(mCalendar))
                                return true;
                                return false;
        } catch (NoSuchFieldException e) {
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {

Motorola Droid2 problem with listview default behaviour

Have you tested your application on all the Android devices ? If you dint then you might be in risk. Some devices in android uses device custom theme to render all its application. Let me explain this with Motorola Droid2 device. I am trying to add a simple ListView in my app. Here is the code which i used to generate it.


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="match_parent" >



public class DroidFixes extends Activity {
 CustomAlertDialog dialog;
 ListView list;
 public void onCreate(Bundle savedInstanceState) {
 String s[] ={"1","2","3"};
 list = (ListView)findViewById(R.id.my_list);
 ArrayAdapter<String> arr = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line,s);

This results in :


If you closely observer you would’ve found a grey background in the lower half of the ListView. This will not be seen in other devices are even in the emulator. This is the custom behavior of ListView which is implemented in Motorola Droid2. This happen because in the above xml layout ListView’s height is specified as wrap_content.


To avoid this there are many solution

  1. Change the ListView height attribute to wrap_content. Since the list content is small it couldn’t occupy the entire screen so the remaining space is filled with the device theam, setting the listview height attribute to wrap_content will wrap perfectly to the list content without occupying any extra space.
  2. If you insist to go with match_parent for listview height attribute then you can set android:overScrollFooter=”@null” this will remove the drawable in the ListView footer content.
  3. If this dint solve your problem then if you have any inflated custom row for this ListView set a background color to that view.


Applying Solution 1

Since i dint use any custom views or layout for this ListView row i am just changing the android:layout_height to “wrap_content” to attain this output.

Applying Solution 2

Things To Note:

Compare the solution 2 with 1. Since ListView’s height is left to match_parent the bottom most divider line is visible if you set it as wrap_content then you wont get the bottom most divider.

Hope this solves your problem 🙂

Using this operator in Java

this is always a reference to the object on which the method was invoked. Consider this example

class ex1
    int x=1,y=1;
    public ex1(int x,int y)
        this.x=x; //this.x refers to the class variable x not to the location function variable
        this.y=y; //for your better understanding in this place this operator can be considered as (this == e)
    public void dis()
        System.out.println("X: "+x+" Y: "+y+this.getClass().getName()); //getClass().getName() returns the object class name
    public static void main(String args[])
        ex1 e = new ex1(10,5);
        ex2 e1 = new ex2();
class ex2

In this above program this operator is used to get the name of the current objects class. this operator cannot be used inside the static method. this operator can also be used to call other methods in the class.


X: 10 Y: 5ex1

Android Development Tools

Development in Android is made very easy by providing the ADT (Android Developer Tools) plug-in for Eclipse. This ADT plug-in provides GUI access for the command line tools.

Lets see about :

  • Logcat
  • Debugger
  • Drag and drop options

Debugger :

In Android Debug comes as an perspective. Open your .Java file from your project in Eclipse IDE and double click on the line where you want to set a break point.

The line int debug=0 is set as the debug line. This means that the program execution will be stopped when this particular line reaches.  Now press F11 key to start debugging. An Conform perspective switch window will appear requesting you to switch to debug perspective. Hit yes to switch to debug perspective. Press F5 to step into the debugging point.

Debugging point

At this point the debug value is 0 which is denoted in the variables window. Press F6 to go to the next line. Now the debug value changes to 1 because of the increment.

Press F8 to completely Run the code.

Drag and Drop :

In Android front end design can be simply done by dragging and dropping. Instead of typing for each and every Views in a design this helps to finish your work soon. To make use of the drag and drop option first right click on the .xml file in your project. Click on the open with -> Android Layout Editor and select Graphical Layout in the bottom of the screen.

Just drag and drop the views from the left widget and place it over the right side screen. There is an excellent video in the developers site regarding Development Tools in android this will help you to understand the various features which will help you save time in designing.