Android SIM change

前端 未结 1 1045
一整个雨季
一整个雨季 2020-12-28 11:00

Is it possible to detect SIM number using TelephonyManager in android at boot startup ,using Service at bootup...

TelephonyManager tm = (TelephonyManager) ge         


        
相关标签:
1条回答
  • 2020-12-28 11:27

    You need to register a broadcast receiver for the boot completion action i.e android.intent.action.BOOT_COMPLETED

    in onReceive of this receiver you can start your service get SIM number with below code lines

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

    Also need to have permission for reading phone number as READ_PHONE_STATE in manifest file.

    you can start service from 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);
    }
    

    }

    0 讨论(0)
提交回复
热议问题