我想知道两个sim卡的运营商名称时,移动是双sim卡。在单一的SIM卡,我得到了操作员的名字,但决斗SIM卡,我不能,虽然经过这么多的搜索和尝试。
如果我在双sim手机上运行我的应用程序,我可以在我的应用程序中同时获得两个sim卡运营商名称,例如:Idea、沃达丰。
编辑:
是否有人知道如何获得IMEI号码的sim卡操作员姓名,然后我有IMEI号码。
代码:
public class MainActivity extends Activity {
Button btnOne, btnTwo;
TextView tvInfo;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnOne = (Button) findViewById(R.id.btnOne);
btnTwo = (Button) findViewById(R.id.btnTwo);
tvInfo = (TextView) findViewById(R.id.tvInfo);
TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this);
boolean isDualSIM = telephonyInfo.isDualSIM();
boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
boolean isSIM2Ready = telephonyInfo.isSIM2Ready();
TelephonyManager manager = (TelephonyManager) getApplicationContext()
.getSystemService(Context.TELEPHONY_SERVICE);
try {
telephonyInfo.imsiSIM1 = telephonyInfo.getDeviceIdBySlot(context,
"getSimSerialNumberGemini", 0);
telephonyInfo.imsiSIM2 = telephonyInfo.getDeviceIdBySlot(context,
"getSimSerialNumberGemini", 1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String number = manager.getLine1Number();
String optName1 = getOutput(getApplicationContext(), "getCarrierName", 0);
String optName2 = getOutput(getApplicationContext(), "getCarrierName", 1);
final String carrierName = manager.getSimOperatorName();
tvInfo.setText(" " + isDualSIM + " " + optName1 + " " + optName2 + " "
+ telephonyInfo.imsiSIM1 + " " + telephonyInfo.imsiSIM2 + " "
+ number + " " + isSIM1Ready + " " + isSIM2Ready);
btnOne.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(
Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivity(intent);
}
});
btnTwo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (carrierName.equalsIgnoreCase("TATA DOCOMO")
|| carrierName.contains("DOCOMO")) {
startService(new Intent(MainActivity.this, USSD.class));
String ussdCode = "*" + "111" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri
.parse("tel:" + ussdCode)));
} else if (carrierName.equalsIgnoreCase("!dea")
|| carrierName.contains("idea")) {
startService(new Intent(MainActivity.this, USSD.class));
String ussdCode = "*" + "121" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri
.parse("tel:" + ussdCode)));
} else if (carrierName.equalsIgnoreCase("AIRTEL")
|| carrierName.contains("airtel")) {
startService(new Intent(MainActivity.this, USSD.class));
String ussdCode = "*" + "123" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri
.parse("tel:" + ussdCode)));
}
}
});
}
private static String getOutput(Context context, String methodName,
int slotId) {
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> telephonyClass;
String reflectionMethod = null;
String output = null;
try {
telephonyClass = Class.forName(telephony.getClass().getName());
for (Method method : telephonyClass.getMethods()) {
String name = method.getName();
if (name.contains(methodName)) {
Class<?>[] params = method.getParameterTypes();
if (params.length == 1 && params[0].getName().equals("int")) {
reflectionMethod = name;
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (reflectionMethod != null) {
try {
output = getOpByReflection(telephony, reflectionMethod, slotId,
false);
} catch (Exception e) {
e.printStackTrace();
}
}
return output;
}
private static String getOpByReflection(TelephonyManager telephony,
String predictedMethodName, int slotID, boolean isPrivate) {
// Log.i("Reflection", "Method: " + predictedMethodName+" "+slotID);
String result = null;
try {
Class<?> telephonyClass = Class.forName(telephony.getClass()
.getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID;
if (slotID != -1) {
if (isPrivate) {
getSimID = telephonyClass.getDeclaredMethod(
predictedMethodName, parameter);
} else {
getSimID = telephonyClass.getMethod(predictedMethodName,
parameter);
}
} else {
if (isPrivate) {
getSimID = telephonyClass
.getDeclaredMethod(predictedMethodName);
} else {
getSimID = telephonyClass.getMethod(predictedMethodName);
}
}
Object ob_phone;
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
if (getSimID != null) {
if (slotID != -1) {
ob_phone = getSimID.invoke(telephony, obParameter);
} else {
ob_phone = getSimID.invoke(telephony);
}
if (ob_phone != null) {
result = ob_phone.toString();
}
}
} catch (Exception e) {
e.printStackTrace();
// Log.i("Reflection", "Result: " + e.printStackTrace());
return null;
}
return result;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
适用于任何android设备。这可能对你有帮助。试试这个!
//above 22
if (Build.VERSION.SDK_INT > 22) {
//for dual sim mobile
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(this);
if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
//if there are two sims in dual sim mobile
List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(0);
SubscriptionInfo simInfo1 = (SubscriptionInfo) localList.get(1);
final String sim1 = simInfo.getDisplayName().toString();
final String sim2 = simInfo1.getDisplayName().toString();
}else{
//if there is 1 sim in dual sim mobile
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String sim1 = tManager.getNetworkOperatorName();
}
}else{
//below android version 22
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String sim1 = tManager.getNetworkOperatorName();
}
用于API
{
SubscriptionManager subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList != null && subscriptionInfoList.size() > 0) {
for (SubscriptionInfo info : subscriptionInfoList) {
String carrierName = info.getCarrierName().toString();
String mobileNo = info.getNumber();
String countyIso = info.getCountryIso();
int dataRoaming = info.getDataRoaming();
}
}
}
由于API版本22,它是可能的
对于操作系统大于android 5.1的设备,请尝试以下代码
List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(getApplicationContext()).getActiveSubscriptionInfoList();
for(int i=0; i<subscriptionInfos.size();i++)
{
SubscriptionInfo lsuSubscriptionInfo = subscriptionInfos.get(i);
Log.d(TAG, "getNumber "+ lsuSubscriptionInfo.getNumber());
Log.d(TAG, "network name : "+ lsuSubscriptionInfo.getCarrierName());
Log.d(TAG, "getCountryIso "+ lsuSubscriptionInfo.getCountryIso());
}
有关更多信息:文档:订阅管理器-Android希望它能有所帮助。和平。
本文向大家介绍Android获取手机SIM卡运营商信息的方法,包括了Android获取手机SIM卡运营商信息的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Android获取手机SIM卡运营商信息的方法,对于Android程序设计有非常实用的价值。分享给大家供大家参考之用。具体方法如下: 主要功能代码如下: 权限代码如下: 希望本文所述对大家的Android程序设计有所帮助
经过论坛上的大量研究,现在我知道没有办法找到双SIM卡手机中两个SIM卡的IMSI或SIM序列号(除了联系制造商)。现在我改变的问题是,我们能检测到手机有两个模拟人生吗?我相信只要有一些情报就可以检测到。我能想到的几个方法是: > 拨打USSD代码并跟踪IMEI号码的日志(我在印度尝试了*139#。它起作用了。)这将给我IMEI号码的SIM卡,我从其中拨打USSD代码。(据推测,这款手机遵循And
我正在做一个项目,在这个项目中,我必须使用移动塔跟踪位置。当sim2处于紧急状态时,它在电话管理器中发出空指针异常。我必须为这两个模拟人生获取LAC、CID、MCC和MNC。我可以使用SubscriptionManager获得MCC、MNC。但我如何才能为这两张sim卡获得LAC和MCC?
我有一个android应用程序可以检测来电,我需要改进这个应用程序,使其能够在duos移动设备上工作。因此,我创建了一个在清单中注册的广播接收器,用于操作:电话状态已更改,在onReceive方法中,我需要检查哪个sim卡接收呼叫。这是我的密码 我运行这个应用程序上的设备4.2 2和其正常工作,但当我运行它上的设备4 4.4所以这个方法不工作,我的意思是,其中sim返回-1在所有情况下。有人能帮帮
本文向大家介绍Android如何获取双卡手机IMEI的方法示例,包括了Android如何获取双卡手机IMEI的方法示例的使用技巧和注意事项,需要的朋友参考一下 前言: 项目中有个统计付费广告转化率的需求,需要获取用户手机的IMEI。但是网上最常见的方法有坑,也就是TelephonyManager.getDeviceId(),这方法有可能获取的是MEID或者空值。然后自己Google了下,发现搜出来
本文向大家介绍Android手机卫士之绑定sim卡序列号,包括了Android手机卫士之绑定sim卡序列号的使用技巧和注意事项,需要的朋友参考一下 现在开始具体 处理每一个导航页面的逻辑,首先看第二个导航页 这里需要实现绑定sim卡序列号的功能,注意添加相应的权限:uses-permission android:name="android.permission.READ_PHONE_STATE"