本文介绍了Android的SIM变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能检测机器人使用TelephonyManager SIM卡号码在开机启动时,使用服务在启动......

  TelephonyManager TM =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
串SS = tm.getSimSerialNumber();
 

解决方案

您需要注册一个广播接收器的启动完成动作即android.intent.action.BOOT_COMPLETED

在此接收器,你就可以开始你的服务的onReceive获得SIM卡数量低于code行

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

也需要有权限读取电话号码READ_PHONE_STATE清单文件。

您可以从广播接收器,启动服务 -

 公共类BootListener扩展的BroadcastReceiver {

@覆盖
公共无效的onReceive(上下文的背景下,意图ARG1){
    意向意图=新的意图(背景下,Myservice.class);
    context.startService(意向);
}
 

}

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();
解决方案

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

}

这篇关于Android的SIM变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:36