Posts

How to get the base class of a Array using java reflection.

If we use Java reflection to get the class of a object like String[][] strings; Java reflection will return [[Ljava.lang.String. But sometimes you may want to get the bases class e.g in this case java.lang.String. Following method can be used to do that. If you want to get the bass class of array object a you use this as Class c=getTypeOfArray(a.getClass()); public static Class getTypeOfArray(Class c){ Class cls=null; while(true){ if(c.isArray()){ c=c.getComponentType(); }else{ cls=c; break; } } return cls; }

GSoC 2012 with Apache Photark, A great experience.

Image
Google summer of code is one of the worlds leading opensource development programs. It is held anually by Google inc. Many enthusiastic students participate each year for this. In every year many number of students try to take part of this program. But nearly 1000 students only get selected for this event.  I was lucky to take part in 2012 program for the first time. I took part on GSoC 2012 under Apache Software Foundation for their incubator project Photark . The interesting thing was my initial plan was to participate on another organization which develops a CMS. I also worked with them nearly one month. But then I realized what they are expecting and what I am interested is not matching. So I looked for another organization and found this interesting project. But then there was little time for application closing period.  So I quickly checcout the code base play with it for little time, drafted a proposal and submitted it. Then Mr. Suhothayan Sriskandara...

How to get current time and date using JavaScript.

Getting system date and time using JavaScript is easy. But some steps has to follow to convert it to a readable format. These functions will help you to get rid of the hassle . //returns date in format 01/01/2012 function getCurrentDate() { var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() return (month + "/" + day + "/" + year); } //returns time in format 05:45 AM function getCurrentTime() { var time = ""; var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); if (minutes < 10) { minutes = "0" + minutes; } var h; if (hours > 12) { h = hours - 12; } if (h < 10) { h = '0' + h; } time += (h + ":" + minutes + " "); if (hours > 11) { time += ("PM"); } else { time += ("AM"); } ...

How to build a maven project without tests

When we build a large project using maven it takes a lot of time because of tests  runs. So we can build quickly by disabling the tests. We can do that using the following command. mvn - Dmaven . test . skip = true install

Using Geolocation API in phone gap

I am currently developing a Phonegap application for Google summer of Code 2012. I encountered some problems when using it and this is how I corrected them. Location not available- In android emulator does not automatically get the location. So we have to send a moc location to the emulator using DDMS perspective in eclipse. Phonegap documentation says to use the below method to get location. navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError); But this gave me an error with error code 2 unable to start geolocation service. I corrected it using the below method. navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError,{ enableHighAccuracy: true }); Note - This is only for testing in the emulator.

How to make a phone call in a Android application

This may a looks like a simple task. Actually it is a simple task. You can do it using few lines of code. But there are only few places which shows how to do it. So I decided to mention it here. public void onCallButtonClicked(View view) { String url = "tel:" + tpNo; Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); intent.setData(Uri.parse(url)); startActivity(intent); }

Android: Using Google maps app to show places in your application

Image
When we are developing android application with maps functionality normally developers tries to use Google maps API for this. But if your requirement is simple it may be more easy and effective to use existing maps application by a intent. In this application I'm going to show how to show the nearest hospital in your application. Note- To make this work your app and emulator must be created using Google APIs not android APIs. (Both are the same but if you are not using Google maps API map application functionality is not available to you). Here is the code, LocationManager  locMgr  = (LocationManager) getSystemService(Context. LOCATION_SERVICE); Location recentLoc = locMgr.getLastKnownLocation( LocationManager.GPS_PROVIDER); double lat = recentLoc.getLatitude(); double lon = recentLoc.getLongitude(); String geoURI = String.format("geo:%f,%f?q= hospital", lat, lon); Uri geo = Uri.parse(geoURI); Intent geoMap = new Inten...