how to get / find your device IMEI number programmatically in andorid


TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String IMEI_Number = telephonyManager.getDeviceId();
Log.d("your device IMEI number -->",IMEI_Number);

Requires permission android.permission.READ_PHONE_STATE.
Dial *#06# to know your IMEI Number or Remove your battery and look for IMEI,you will find it.

Advertisements

How to get / find your android device id or serial number programmatically


String device_id = Build.SERIAL; /* This string is available from api level 9 */
Log.d("your device id or serial number -->", device_id);

how to get / find UUID of an android device programmatically


 String device_uuid = Secure.getString(this.getContentResolver(),Secure.ANDROID_ID);
 Log.d("your device uuid --> ", device_uuid);

How to convert android project to executable .jar file

Right Click on Project –> Export —> Java –> JarFile

Window will appear Select Resources to Export

Select only the src checkbox ie the (pacakages) in Top-Left Window.

Don’t Select anything in Top-Right Window if some thing is selected  remove the tick mark

Select only the first Checkbox in the middle left window ie  Export generates Class Files and Resources

Select the Export Destination ie the path where u want to save ur jar file

In Options Select only Compress the contents of the jar file

Click Finish u will find ur jar file

Now if u want to add this jar file to any project. It is very simple

Right click on project –> Select Properties –> Java Build Path —> libraries –> Add External Jar Files –> Click OK

Now just Build your project U WILL find the jar file

What is JAVA and brief history of JAVA

As we know that JAVA was developed by Sun microsystems, now here is the berief history of how the language originated.
In 1990 Sun Microsystems Inc(US) has conceived a project to develop software for consumer electronic devices that could be controlled by a remote.This project was called Stealth Project but later its name was changed to Green Project.

But here the major problem was that when using C or C++ for developing the Project, but these languages are system dependent languages and hence could not be used on various processors, which the electronic device might use. So there is a need of another languages which should  be completely system independent. Now they started developing a language which was initially called as Oak. Since this name was registered by another company, later it was changed to JAVA.

But why they choose the name Java???While theey were developing language, they were consumed a lot of tea, so they felt that they were able to devlop a better lnguage because of this tea they consumed and hence, they fixed the name Java.

By September 1994, they developed a java-based Web browser, names as HOTJava.HotJava was the first browser having the capabilities of executing applets. This time, Java’s potential in the context of world wide web was recognised.

Sun formally announced Java & HotJava at SunWorld conference in 1995.On January 1996, JDK 1.0 was relleased. Today more than 5 millions people use java and more than 2 billion devices run java.

The above snippet is taken from http://bharatsoft.blogspot.in/2010/11/introduction-and-history-of-java.html

How to know/find the version of jdk/java which is installed in linux/ubuntu system

Open Terminal and type

java -version

or

javac -version

how to know find the path of java/jdk in ubuntu/linux

 /usr/lib/jvm  is the path where the jdk is located.

How to run/execute native C/C++ code in android using NDK in linux operating system

Step 1 : Install NDK (nothing but just extract the zip file)

Step 2 : Create jni folder inside the project root folder

Step 3 : Create Android.mk file inside jni folder which should contain the following content

/****************** Android.mk starts here **************************************************/

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := hellojni
LOCAL_SRC_FILES := hellojni.c

include $(BUILD_SHARED_LIBRARY)

/****************** Android.mk ends here **************************************************/

where hellojni is the name of the your c file.

Step 4 : Create a hellojni.c file using JNI syntax.

For a simple hellojni.c file Please refer the file below

	/****************** hellojni.c starts here **************************************************/

	#include <string.h>
	#include <jni.h>

	jstring Java_com_example_MainActivity_stringFromJNI(JNIEnv* env,jobject thiz)
	{
	    return (*env)->NewStringUTF(env, "Hello from JNI !");
	}

	/****************** hellojni.c ends here **************************************************/
	 

Please note the follwing things

1) stringFromJNI is the name of the native method say function in C language.
2) MainActivity is the activity name in which you have declared the above method.
3) com.example represents the package name of the activity MainActivity.java

Note: The above method if executed will return “Hello from JNI !” string.

Step 5 : Declare the method stringFromJNI in MainActivity as native as shown below

         public native String stringFromJNI();
 	 

Step 6 : Load the library “hellojni” in your MainActivity inside a static block as shown below

         static
	 {
	    System.loadLibrary("hellojni");
         }
         

Step 7 : Open Terminal

Go to the project path
To know the project path —-> Right Click On Project –> Properties –> Location
Copy it and execute the following command

Eg: cd <project path>Press Enter

Now Extract the ndk zip file which you have downloaded before and open it. You should find a file named ndk-build.
Now copy the path of your ndk and execute the following command

Eg: <ndk path>/ndk-build Press Enter

The above command will compile your hellojni.c and generates a shared library in the jni folder of your project
Output should be as follows —->

Compile thumb : hellojni <= hellojni.c

SharedLibrary : libhellojni.so

Install : libhellojni.so => libs/armeabi/libhellojni.so

Step 8: Right Click On Project –> Refresh
You should observe the following

1) obj folder which contains local –> armeabi
armeabi folder –> objs –> libhellojni.so
objs folder –> hellojni
hellojni folder –> hellojni.o and hellojni.o.d files.

2) libs folder(will be created if not exists before) –> armeabi –> libhellojni.so

The above scenario indicates that your hellojni.c file is being compiled to library file ie libhellojni.so by CPU architecture(armeabi) of your device and it is being added to your build path.

Step 9 : Call the native method inside your activity as shown below

        String message = stringFromJNI();
	

Step 10: Run the project

The  stringFromJNI method will return “Hello from JNI !” .

Note: You should require min SDK Version 1.5 to use NDK 

How to calculate distance between any two geo points (latitudes and longitudes) in android


/**
 * @param fromLatitude
 * @param fromLongitude
 * @param toLatitude
 * @param toLongitude
 * @return distance between the two latitudes and longitudes in kms.
 */
 public static double calculateDistance(double fromLatitude,double fromLongitude,double toLatitude,double toLongitude)
 {

 float results[] = new float[1];

try {
 Location.distanceBetween(fromLatitude,fromLongitude, toLatitude, toLongitude, results);
 } catch (Exception e) {
 if (e != null)
 e.printStackTrace();
 }

 int dist = (int) results[0];
 if(dist<=0)
 return 0D;

 DecimalFormat decimalFormat = new DecimalFormat("#.##");
 results[0]/=1000D;
 String distance = decimalFormat.format(results[0]);
 double d = Double.parseDouble(distance);
 return d;
 }

How to install java in windows and how to set class path in java

Setting PATH and CLASS variable in Java is not so difficult, You have to follow some steps and you have done…Just follow these steps and you have done!!!

First of all Install Java( either 5,6 or 7). You can download it from its official website.

After installing java go to C:  then go to Program files here look for folder named java…

Now open that Java folder here you will find two folders named  jdk1.6.0_20(if you are using java6) and jre6. Just click on jdk1.6.0_20

now after opening jdk1.6.0_20  open the “bin”  folder and copy the whole path as shown in the following pictures…

Here you have done First step..let proceed towards second step…

Go to “My computer”  and right click on it….

double click on MY COMPUTER

Now click on “Properties”  If you are using Windows7 then it will look like this…

After this double click on “Advance System Settings” as indicated in above figure it will opened as…

Here click on Environment variable a new window will opened like this…

now on  System Variable window click on new after that a window will opened in which give
variable name = PATH and variable value = “the whole path” you copied from bin folder its look like…

now press OK button. Here you set the path of the java, Now you have to set the CLASS for this again go to Environment variables.. Here on “Users Variable” window, Click on new and give the following value..

variable name = CLASS and variable value = “the whole path” you copied from  lib folder.

All this are  shown in the following pictures….

Alas!!!! You have finished all your works of setting PATH and CLASS variables of Java….So enjoy Your Java Coding….

The above snippet is taken from http://bharatsoft.blogspot.in/2010/08/setting-path-and-classpath-in-javahow.html