发送消息,SIM2 [英] send message with SIM2
问题描述
我把两个发送按钮在我的布局文件中的(mysend.xml)
I'm put two send buttons in my layout file (mysend.xml):
- 与SIM1 SEND(机器人:ID =@ + ID / SEND1)
- 与SIM2 SEND(机器人:ID =@ + ID / send2)
我的code在我的Java文件中的(MySend.java)
My code in my java file (MySend.java)
public class MySend extends Activity {
public static boolean sendSMS(Context ctx, int simID, String nomor, String centerNum, String pesan, PendingIntent sentIntent, PendingIntent deliveryIntent) {
String name;
try {
if (simID == 0) {
name = "isms1";
// for model : "Philips T939" name = "isms0"
} else if (simID == 1) {
name = "isms2";
} else {
throw new Exception("can not get service which for sim '" + simID + "', only 0,1 accepted as values");
}
Method method = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", String.class);
method.setAccessible(true);
Object param = method.invoke(null, name);
method = Class.forName("com.android.internal.telephony.ISms$Stub").getDeclaredMethod("asInterface", IBinder.class);
method.setAccessible(true);
Object stubObj = method.invoke(null, param);
if (Build.VERSION.SDK_INT < 18) {
method = stubObj.getClass().getMethod("sendText", String.class, String.class, String.class, PendingIntent.class, PendingIntent.class);
method.invoke(stubObj, nomor, centerNum, pesan, sentIntent, deliveryIntent);
} else {
method = stubObj.getClass().getMethod("sendText", String.class, String.class, String.class, String.class, PendingIntent.class, PendingIntent.class);
method.invoke(stubObj, ctx.getPackageName(), nomor, centerNum, pesan, sentIntent, deliveryIntent);
}
return true;
} catch (ClassNotFoundException e) {
Log.e("apipas", "ClassNotFoundException:" + e.getMessage());
} catch (NoSuchMethodException e) {
Log.e("apipas", "NoSuchMethodException:" + e.getMessage());
} catch (InvocationTargetException e) {
Log.e("apipas", "InvocationTargetException:" + e.getMessage());
} catch (IllegalAccessException e) {
Log.e("apipas", "IllegalAccessException:" + e.getMessage());
} catch (Exception e) {
Log.e("apipas", "Exception:" + e.getMessage());
}
return false;
}
}
这code里面的公共无效的onCreate(最终捆绑savedInstanceState){
// for send1 button
MySend.sendSMS(MySend.this,0,nomor,null,pesan,null,null);
// for send2 button
MySend.sendSMS(MySend.this,1,nomor,null,pesan,null,null);
我的问题
如果我是点击按钮SEND1,这是100%的工作和发送消息,SIM1,
但是如果我点击send2按钮,该消息将不会被发送。
If i'm click on send1 button, it's 100% work and sent message with SIM1, but if i'm click on send2 button, the message won't sent.
顺便说一句,对不起,我的英语不好
btw,sorry for my bad english
推荐答案
有关我,code为SIM1但SIM2什么工作得很好发生。纵观日志空指针异常被抛出。所以,问题是与 NAME = isms2
。对于我的手机(芯片组小号preadtrum),因为其SIM1是isms0和SIM2是isms1。您可以检查你的dumpsys文件,或在亚行外壳下面code:
For me that code worked fine for sim1 but for sim2 nothing happened. Looking at the log Nullpointer exception was being thrown. So the problem was with name = isms2
. For my phone (chipset Spreadtrum), for sim1 its was isms0 and for sim2 it was isms1. You can check yours in the dumpsys file, or with the following code in adb shell:
adb shell service list | grep isms
这将列出您的设备提供的主义。对于我的设备是以下的输出:
This will list the isms available in your device. For my device following was the output:
8 isms: [com.android.internal.telephony.ISms]
12 isms1: [com.android.internal.telephony.ISms]
16 isms0: [com.android.internal.telephony.ISms]
请查看我的答案<一个href=\"http://stackoverflow.com/questions/27351936/how-to-send-a-sms-using-smsmanager-in-dual-sim-mobile/30677542#\">here.
这篇关于发送消息,SIM2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!