Android Application Development Cookbook: 93 Recipes for Building Winning Apps by Wei-Meng Lee

Get full access to Android Application Development Cookbook: 93 Recipes for Building Winning Apps and 60K+ other titles, with a free 10-day trial of O'Reilly.

There are also live events, courses curated by job role, and more.

Recipe 4.7 Getting the Phone Number, IMEI, and SIM Card ID

Android Versions Level 1 and above Permissions android.permission.READ_PHONE_STATE Source Code Download from Wrox.com SIMCardID.zip

If you are writing a security application, you might want to know whether the user has changed the SIM card on the phone. For example, the first time your application is run on the device, you can obtain the SIM card ID of the device and store it in your application. Every time the phone switches from AirplaneModeON to AirplaneModeOFF (see previous recipe for how to detect this), you would then check the SIM card ID with the one that you previously recorded. If you detect that the SIM ID has changed, you might want to programmatically send an SMS message to another phone so that you can be notified. This scenario is common when your phone is stolen. Usually, thieves will swap out the current SIM card with their own. In this case, when the phone is restarted after putting in a new SIM card, your application will obtain the SIM card ID and compare it against its previously recorded SIM ID. Besides the SIM card ID, another piece of useful information about the phone is the IMEI — International Mobile Equipment Identity. An IMEI number is a number that is used to uniquely identify a mobile device. Knowing the IMEI of a device allows it to be identified when it is recovered. This recipe shows you how to obtain all this information.

Solution

To get the details about your phone, .

Get Android Application Development Cookbook: 93 Recipes for Building Winning Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.