Storing IMEI and other Device Personalization Data to Phone

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Storing IMEI and other Device Personalization Data to Phone

Postby Steve.Scherer » Mon Sep 15, 2008 7:27 pm

What is the mechanism in Android to store and IMEI? I found the following post -- Getting IMSI / IMEI (SIM / Device Unique IDs)

This post gives a good example for reading IMEI or IMSI from a phone. This and other device specific settings and data may have vendor specific implementation. I'm assuming there are native libraries that would have to be modified for storing or reading the IMEI and other device data. Specifically, which library has the code for storing and retrieving IMEI?


Example of retrieving IMEI and IMSI
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String myIMSI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
  2.  
  3. // within my emulator it returns:   310995000000000
  4.  
  5.  
  6.  
  7. String myIMEI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMEI);
  8.  
  9. // within my emulator it returns:   000000000000000
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Steve.Scherer
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Sep 15, 2008 6:53 pm

Top

Postby alex2308 » Wed Sep 24, 2008 12:24 pm

you cant change IMEI/IMSI
alex2308
Developer
Developer
 
Posts: 34
Joined: Wed Jun 11, 2008 1:37 pm

1.0 change?

Postby eee333 » Fri Sep 26, 2008 1:18 am

anyone know what this has changed to in 1.0?
eee333
Freshman
Freshman
 
Posts: 9
Joined: Tue Mar 25, 2008 10:35 pm

Re: Storing IMEI and other Device Personalization Data to Ph

Postby ninor » Fri Sep 26, 2008 8:36 am

Steve.Scherer wrote:What is the mechanism in Android to store and IMEI? I found the following post -- Getting IMSI / IMEI (SIM / Device Unique IDs)

This post gives a good example for reading IMEI or IMSI from a phone. This and other device specific settings and data may have vendor specific implementation. I'm assuming there are native libraries that would have to be modified for storing or reading the IMEI and other device data. Specifically, which library has the code for storing and retrieving IMEI?


Example of retrieving IMEI and IMSI
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String myIMSI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
  2. // within my emulator it returns:   310995000000000
  3.  
  4. String myIMEI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMEI);
  5. // within my emulator it returns:   000000000000000
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Hello,

These methods/utilities moved its situation in SDK 0.9:
(I don't know where's in v1.0r1)

Several GSM subscriber and device-related system properties are moved to new permission-checked API:

PROPERTY_IMEI
PROPERTY_IMEISV
PROPERTY_IMSI
PROPERTY_ICCID
PROPERTY_LINE1_NUMBER
PROPERTY_LINE1_TAG
PROPERTY_LINE1_VOICE_MAIL_NUMBER
PROPERTY_LINE1_VOICE_MAIL_TAG

You can now access these phone/subscriber properties through the new PhoneSubInfoManager, using the IPhoneSubInfo interface. Note that, to get access phone/subscriber information through the IPhoneSubInfo interface, you must add the permission ACCESS_PHONE_SUB_INFO to your application's manifest file. For example:

<uses-permission android:name="android.permission.ACCESS_PHONE_SUB_INFO" />
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby MrSnowflake » Wed Oct 01, 2008 4:35 pm

Here they are :) :
mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = mTelephonyMgr.getDeviceId();
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby ninor » Wed Oct 01, 2008 5:20 pm

Thanks MrSnowFlake! :)
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top

Postby MrSnowflake » Wed Oct 01, 2008 6:22 pm

I just found this out myself, I use it to determine if the activity is running on the emulator (imei: 0000000000).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Artur79 » Sun Oct 12, 2008 7:03 pm

MrSnowflake wrote:mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = mTelephonyMgr.getDeviceId();

I don't know what IDE are you using, but on Eclipse I had to change this code before run, to:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TelephonyManager mTelephonyMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  2. String imei = mTelephonyMgr.getDeviceId();
  3.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


where context is object defined in onReceive():

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onReceive(Context context, Intent intent) { ...
  2.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I don't understand why I have to use (TelephonyManager) before context.getSystemService.... getSystemService() can return different types of objects ? Maybe someone good at java can explain me, please.

permission in manifest should be
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  2.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


maybe it's obvious for experienced users, but for fresh ones like me, may be helpful :)
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby ninor » Sun Oct 12, 2008 7:32 pm

Hi Artur,

The explanation for that explicit cast, is that Context.getSystemService() returns a plain and generic object.
Because an object can be *any* kind of class/object/value, you have to specify the class you want to convert object into, before assigning to the mTelephonyMgr object.

Yes, it's a TelephonyManager object, but you *must* explicitly cast it prior assigning.

This is a main difference between java and other languages, like C++ for instance.

Hope this helps.
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby Artur79 » Sun Oct 12, 2008 7:40 pm

ninor wrote:Hope this helps.

yes, cheers :)
so always when method definition is like here ...
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public abstract Object getSystemService(String name)
  2.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

... I need to cast ?
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby ninor » Sun Oct 12, 2008 9:36 pm

That's right!

Dont' forget that even you cast to any type, you have to check that the object you're passing is that type's type, or you'll face a nice Exception...
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby gymshoe » Thu Nov 06, 2008 5:37 am

This is very helpful, Thanks!

I guess I don't understand why the imei is 00000000000.
I guess it could be, but since:
"The International Mobile Equipment Identity or IMEI (pronounced /aɪˈmiː/) is a number unique to every GSM and UMTS and iDEN mobile phone as well as some satellite phones."

I would think that the imei would be a specific number, not zeros... For instance the phone number of the emulator is 155555218135, not 0000000000.

What do you mean by :
" I use it to determine if the activity is running on the emulator (imei: 0000000000)."

Isn't the imei unique to the phone and not the acivity?

thanks!
Jim
gymshoe
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Sep 10, 2008 6:07 am

Postby MrSnowflake » Thu Nov 06, 2008 10:35 am

If the application is running on the emulator, I can fetch the EMEI number at it will be 00000000..0. When I fetch it on a real phone it will be something else.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby dkkundudolan » Wed Dec 24, 2008 10:35 am

Hi MrSnowflake,

Can you be some more specofic about the IMSI no in v1.0?
I tried with the process what you have mentioned, but application is crashed.
Showing the message "App has stopped unexpectedly. Please try again".

Hope a reply.... its urgent.

Thanks.
dkkundudolan
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Mon Mar 03, 2008 12:50 pm

Postby MrSnowflake » Wed Dec 24, 2008 11:17 am

You could try to find out what caused this error, by looking at your log... That might be a good start... And make sure you have the permission someone mentioned before.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top
Next

Return to General

Who is online

Users browsing this forum: No registered users and 3 guests