Yusuf,
Wont the following work ?
globals.setDevice((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE));
Globals {
public void setDevice(TelephonyManager myDevice){this.myDevice = myDevice ;}
public initialize(){
myDevice = Globals.getInstance().getDevice();
this.deviceID = myDevice.getDeviceId() ;
this.networkType = myDevice.getNetworkType() ;
this.phoneType = myDevice.getPhoneType() ;
this.simSerialNumber = myDevice.getSimSerialNumber();
}
}
I am getting this.deviceID as null, networkType as 0, phoneType = 0,
simSerialNumber=0.
Please help
Siddharth
On Tue, Jun 30, 2009 at 6:11 AM, Yusuf T. Mobile <[email protected]>wrote:
>
> Here's some code to get you on your way:
>
>
> Yusuf Saib
> Android
> ·T· · ·Mobile· stick together
> The views, opinions and statements in this email are those of the
> author solely in their individual capacity, and do not necessarily
> represent those of T-Mobile USA, Inc.
>
> ------
>
>
> import java.io.IOException;
> import java.io.InputStream;
>
> import android.content.Context;
> import android.os.Build;
> import android.telephony.TelephonyManager;
> import android.telephony.gsm.GsmCellLocation;
>
> public class DeviceInfomation {
>
> private MonitorActivity mon;
>
> /**
> *
> * @param monAct
> * the monitor activity.
> */
> public DeviceInfomation(MonitorActivity monAct) {
> this.mon = monAct;
> }
>
> public String getDeviceInfo() {
> String result = "\t<device>\n";
> result += getSoftwareRevision();
> result += getHardwareRevision();
> result += "\t\t<loc>" + getCellID() + "</loc>\n";
> result += "\t\t<msisdn>" + getMsisdn() + "</msisdn>\n";
> result += "\t\t<imei>" + getImei() + "</imei>\n";
> result += "\t</device>\n";
> return result;
> }
>
> /**
> *
> * @return Returns the IMEI.
> */
> private String getImei() {
> TelephonyManager mTelephonyMgr = (TelephonyManager)
> mon.getSystemService(Context.TELEPHONY_SERVICE);
> return mTelephonyMgr.getDeviceId();
> }
>
> /**
> *
> * @return Returns the MSISDN.
> */
> private String getMsisdn() {
> TelephonyManager mTelephonyMgr = (TelephonyManager)
> mon.getSystemService(Context.TELEPHONY_SERVICE);
> return mTelephonyMgr.getLine1Number();
> }
>
> /**
> *
> * @return Returns the cell ID.
> */
> private int getCellID() {
> TelephonyManager mTelephonyMgr = (TelephonyManager)
> mon.getSystemService(Context.TELEPHONY_SERVICE);
> GsmCellLocation location = (GsmCellLocation)
> mTelephonyMgr.getCellLocation();
> return location.getCid();
> }
>
> /**
> *
> * @return Returns the software revision.
> */
> private String getSoftwareRevision() {
> String result = "\t<soft>\n";
> Runtime runtime = Runtime.getRuntime();
> try {
> Process proc = runtime.exec("cat /proc/version");
> int exit = proc.waitFor();
> if (exit == 0) {
> String content = getContent(proc.getInputStream());
> int index = content.indexOf(')');
> if (index >= 0) {
> result += "\t\t<kernel>" + content.substring(0,
> index +1)
> + "</kernel>\n";
> }
> }
> } catch (IOException e) {
> e.printStackTrace();
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> result += "\t\t<buildNumber>" + Build.PRODUCT +
> Build.VERSION.RELEASE
> + "</buildNumber>\n";
> result += "\t</soft>\n";
> return result;
> }
>
> private String getHardwareRevision() {
> String result = "\t<hard>\n";
> Runtime runtime = Runtime.getRuntime();
> try {
> Process proc = runtime.exec("cat /proc/cpuinfo");
> int exit = proc.waitFor();
> if (exit == 0) {
> String content = getContent(proc.getInputStream());
> String [] lines = content.split("\n");
> String [] hInfo = {
> "Processor", "Hardware", "Revision"
> };
> if (lines != null) {
> for (String line: lines) {
> for (String info: hInfo) {
> int index = line.indexOf(info);
> if (index >= 0) {
> result += "\t\t<" + info.toLowerCase()
> + ">";
> int vIndex = line.indexOf(':');
> result += line.substring(vIndex + 1);
> result += "\t\t</" + info.toLowerCase
> () + ">";
> }
> }
> }
> }
> }
> } catch (IOException e) {
> e.printStackTrace();
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> result += "\t</hard>\n";
> return result;
> }
>
> /**
> *
> * @param input
> * the input stream.
> * @return Returns the content string of the input stream.
> *
> * @throws IOException
> * the Java exception.
> */
> public static String getContent(InputStream input) throws
> IOException {
> if (input == null) {
> return null;
> }
> byte [] b = new byte [1024];
> int readBytes = 0;
> String result = "";
> while ((readBytes = input.read(b)) >= 0) {
> result += new String(b, 0, readBytes);
> }
> return result;
> }
> }
>
>
> On Jun 25, 7:06 am, "Ewan Benfield" <[email protected]> wrote:
> > Hi,
> >
> > Take a look at android.os.Build.
> >
> > You can find the code that runs when you look up this information via
> > Settings > About Phone from the home screen in
> > com.android.settings.DeviceInfoSettings.java in the Android sources. (in
> > packages/apps/Settings/src/com/android/settings)
> >
> > cheers,
> > Ewan
> >
> > On Thu, 25 Jun 2009 11:02:29 +0100, swapnil <[email protected]>
> > wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hello All,
> >
> > > Is it possible to get :
> > > The ESN Number of a phone
> > > The Hardware version
> > > The Software version of a phone.
> >
> > > Is there any way to get this stuff.
> >
> > > Thanks in advance.
> >
> > > Swapnil Dalal.
> >
> > --
> > Ewan Benfield
> >
> > http://www.telesense.co.uk
> > tel: 0845 643 5691 (+44 845 643 5691)
> > mob: +44 (0) 77859 26477
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---