Change Android SIM Card

Is it possible to determine the SIM card number using TelephonyManager in android at boot, using Service at boot ...

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String ss=tm.getSimSerialNumber(); 
+6
source share
1 answer

You need to register a broadcast receiver for the download completion action ie android.intent.action.BOOT_COMPLETED

In the onReceive of this receiver, you can start your service to get a SIM number with a line below the code

  TelephonyManager telephoneMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String phoneNumber = telephoneMgr.getLine1Number(); 

You must also have permission to read the phone number as READ_PHONE_STATE in the manifest file.

you can start the service from the broadcast receiver as -

  public class BootListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { Intent intent = new Intent(context,Myservice.class); context.startService(intent); } 

}

+10
source

Source: https://habr.com/ru/post/904450/


All Articles