Is there a way that I can access the other sim in my android? I have an android Cherry Mobile Orbit which is a dual sim android phone. I want to develop an SMS application for my phone, but only the 1st sim will be access. I want to access the other sim, so that when i press enter to send the message, there will be a prompt, that which sim the message will be sent. I know that it's propreitary, but the phone manufacturer has no feedback about it. Is there any other way? tweaking or something?
4 回答
我认为你可以使用 dex2jar 或 apktool 来反转那些在双卡设备上运行的应用程序,一旦你找到相关的“服务管理器”,“电话管理器”,一些接口存根,或者像“Gemini”这样的关键词,你就可以使用Java Reflection,反射这个类的所有方法。然后你就可以实现这个目标。
此方法可用于从 2 个 SIM 中选择一个 SIM!
//above Android API 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 API 22
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String sim1 = tManager.getNetworkOperatorName();
}
然后发送短信,您可以使用以下方法
public static boolean sendSMS(Context context, String smsText) {
SmsManager smsMan = SmsManager.getDefault();
SharedPreferences prefs = context.getSharedPreferences("uinfo", MODE_PRIVATE);
String sim = prefs.getString("sim", "No name defined");
String simName = prefs.getString("simName", "No name defined");
String toNum = "";
try {
if (Build.VERSION.SDK_INT > 22) {
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(context);
if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
int simID = Integer.parseInt(sim);
List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(simID);
ArrayList<String> parts = smsMan.divideMessage(smsText);
SmsManager.getSmsManagerForSubscriptionId(simInfo.getSubscriptionId()).sendMultipartTextMessage(toNum, null, parts, null, null);
}else{
ArrayList<String> parts = smsMan.divideMessage(smsText);
smsMan.sendMultipartTextMessage(toNum, null, parts, null, null);
}
return true;
}else{
ArrayList<String> parts = smsMan.divideMessage(smsText);
smsMan.sendMultipartTextMessage(toNum, null, parts, null, null);
}
} catch (Exception e) {
}
return false;
}
官方目前没有支持此功能的 API,您必须联系设备制造商。
假设您正在为自己的手机开发应用程序,并且您愿意费力找出sim_id
分配给每张 SIM 卡的 ID ( )(可能通过检查手机的日志输出,搜索sim_id
,这就是我做了),您可以使用以下代码设置短信发送的默认 SIM 卡:
int simId = <place desired SIM ID here>;
Intent simIntent = new Intent("android.intent.action.SMS_DEFAULT_SIM");
simIntent.putExtra("simid", simId);
sendBroadcast(simIntent);
结合其他一些 UI 提示内容(用于实际“选择”首选 SIM 卡),这应该可以解决问题。
我完全不确定这种方法是否适合您(尽管代码看起来很“标准”);我在我的 Mlais MX28(带有定制的 ROM)上反复试验发现了这一点。但我想它仍然值得一试。:)
更新:
奇怪的是,在对我正在开发的应用程序进行了几次更新后,该解决方案意外停止工作。但我遇到了另一种方式(这似乎更有希望)。(我相信这也可以扩展到其他 SIM 选择场景,因为设置缓存包含带有name
s gprs_connection_sim_setting
、voice_call_sim_setting
等video_call_sim_setting
的条目。)
ContentValues val = new ContentValues();
val.put("value", "here goes the preferred SIM ID");
getContentResolver().update(Uri.parse("content://settings/system"), val, "name='sms_sim_setting'", null);
(不幸的是,这需要android.permission.WRITE_SETTINGS
许可。)