Android SIM change

泄露秘密 提交于 2019-12-18 11:13:56

问题


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

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String ss=tm.getSimSerialNumber();

回答1:


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);
}

}



来源:https://stackoverflow.com/questions/8629766/android-sim-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!