Android Telephone manager to detect sim

后端 未结 3 1121
日久生厌
日久生厌 2021-01-02 21:59

I am working on an Android auto-start app that\'s basically dependent on SIM card state. When my app auto starts I need it to check where the SIM card has been changed or n

相关标签:
3条回答
  • 2021-01-02 22:23

    Do you try your app on android emulator? Maybe you must try your application on android phone directly, i think the android emulator cannot support your application.

    0 讨论(0)
  • 2021-01-02 22:25

    Below code will help you to fetch the SIM Serial No

    TelephonyManager mTelephonyMgr =
    (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    
    String sSimSerial = mTelephonyMgr.getSimSerialNumber(); 
    

    Set the following permission on Android Manifest file

    android.permission.READ_PHONE_STATE

    0 讨论(0)
  • 2021-01-02 22:31

    If you want to react to a Sim change you need to set a listener:

    final TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    
        tm.listen(new PhoneStateListener() {
            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                //Code in here executed on Sim State change
            }
    
            @Override
            public void onDataConnectionStateChanged(int state) {
    
            }
    
    0 讨论(0)
提交回复
热议问题