How to get the ANDROID SDK Version? How to get your Phone’s IP Address in ANDROID? Also how to get your phone number from the phone?

By | January 23, 2011

Please checkout the “LogCat” for the output.
If you don’t know about Logcat In Eclipse “Go to Window->showView and search for Logcat”.

package com.ip;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

public class Get_IP extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
//        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
//        int ipAddress = wifiInfo.getIpAddress();
//        String ip = intToIp(ipAddress);

StringBuffer buf = new StringBuffer();
buf.append("VERSION.RELEASE {"+Build.VERSION.RELEASE+"}");
buf.append("nVERSION.INCREMENTAL {"+Build.VERSION.INCREMENTAL   +"}");
buf.append("nVERSION.SDK {"+Build.VERSION.SDK+"}");
buf.append("nBOARD {"+Build.BOARD+"}");
buf.append("nBRAND {"+Build.BRAND+"}");
buf.append("nDEVICE {"+Build.DEVICE+"}");
buf.append("nFINGERPRINT {"+Build.FINGERPRINT+"}");
buf.append("nHOST {"+Build.HOST+"}");
buf.append("nID {"+Build.ID+"}");
System.out.println("build"+buf);

System.out.println("Phone Number = " + getMy10DigitPhoneNumber());
}
public String intToIp(int i) {

  return ((i >> 24 ) & 0xFF ) + "." +
  ((i >> 16 ) & 0xFF) + "." +
  ((i >> 8 ) & 0xFF) + "." +
  ( i & 0xFF) ;
}
private String getMyPhoneNumber(){
 TelephonyManager mTelephonyMgr;
 mTelephonyMgr = (TelephonyManager)
 getSystemService(Context.TELEPHONY_SERVICE);
 return mTelephonyMgr.getLine1Number();
 }

 private String getMy10DigitPhoneNumber(){
 String s = getMyPhoneNumber();
 return s.substring(2);
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

How to get the ANDROID SDK Version? How to get your Phone’s IP Address in ANDROID? Also how to get your phone number from the phone?

By | January 23, 2011

Please checkout the “LogCat” for the output.
If you don’t know about Logcat In Eclipse “Go to Window->showView and search for Logcat”.

package com.ip;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

public class Get_IP extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
//        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
//        int ipAddress = wifiInfo.getIpAddress();
//        String ip = intToIp(ipAddress);

StringBuffer buf = new StringBuffer();
buf.append("VERSION.RELEASE {"+Build.VERSION.RELEASE+"}");
buf.append("nVERSION.INCREMENTAL {"+Build.VERSION.INCREMENTAL   +"}");
buf.append("nVERSION.SDK {"+Build.VERSION.SDK+"}");
buf.append("nBOARD {"+Build.BOARD+"}");
buf.append("nBRAND {"+Build.BRAND+"}");
buf.append("nDEVICE {"+Build.DEVICE+"}");
buf.append("nFINGERPRINT {"+Build.FINGERPRINT+"}");
buf.append("nHOST {"+Build.HOST+"}");
buf.append("nID {"+Build.ID+"}");
System.out.println("build"+buf);

System.out.println("Phone Number = " + getMy10DigitPhoneNumber());
}
public String intToIp(int i) {

  return ((i >> 24 ) & 0xFF ) + "." +
  ((i >> 16 ) & 0xFF) + "." +
  ((i >> 8 ) & 0xFF) + "." +
  ( i & 0xFF) ;
}
private String getMyPhoneNumber(){
 TelephonyManager mTelephonyMgr;
 mTelephonyMgr = (TelephonyManager)
 getSystemService(Context.TELEPHONY_SERVICE);
 return mTelephonyMgr.getLine1Number();
 }

 private String getMy10DigitPhoneNumber(){
 String s = getMyPhoneNumber();
 return s.substring(2);
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *