Returns the unique subscriber ID, for example, the IMSI for a GSM phone. - Android Hardware

Android examples for Hardware:GSM

Description

Returns the unique subscriber ID, for example, the IMSI for a GSM phone.

Demo Code


//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    /**// www .  j av  a2s  .  c om
     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
     * Return null if it is unavailable.
     * <p>
     * Requires Permission:{@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     * @return 
     */
    public static String obtainIMSI(Context context) {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imsi = tm.getSubscriberId();
        if (imsi == null) {
            imsi = "";
        }
        return imsi;
    }
}

Related Tutorials