Android SIM change

Deadly 提交于 2019-11-30 02:29:12

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

}

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