2016-03-03 48 views
3

我正在尝试开发面向展讯芯片组智能手机的Android应用程序。这个应用程序需要指定哪个SIM卡(SIM1或SIM2)发送短信或执行电话。Spreadtrm芯片组。 Dual Sim Application从指定的SIM插槽发送短信。 (<22)

我能找到一个适用于Mediatek API here的API,它可以作为android studio的插件。

我试图使用在this post中提到的adb shell。这没有奏效,两个命令都通过sim1发送了短信。两个命令:

1. service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText" 2. service call isms2 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText"

当我列出了服务电话,有telephony.registry0和telephony.registry1。

我试图使用this post中提到的反射。短信仅从sim1发送。

难道没有任何API或插件来使用展讯

注:我知道这是不是棒棒糖和Android的更高版本一个prolem。但我正在尝试为KitKat版本构建此应用程序。

P.S.我甚至尝试联系芯片组公司。但遗憾的是没有回应。

+0

我也陷在同样的问题? :P – Y2K

回答

1

您需要为此使用反射。以下为我工作代码:

public class SimUtil { 

public static boolean sendSMS(Context ctx, int simID, String toNum, String centerNum, String smsText, PendingIntent sentIntent, PendingIntent deliveryIntent) { 
String name; 

try { 
    if (simID == 0) { 
     name = "isms0"; 
    } else if (simID == 1) { 
     name = "isms1"; 
    } else { 
     throw new Exception("can not get service which for sim '" + simID + "', only 0,1 accepted as values"); 
    } 

    try 
    { 
     Method method = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", new Class[]{String.class}); 
     method.setAccessible(true); 
     Object param = method.invoke(null, new Object[]{name}); 
     if (param == null) 
     { 
      throw new RuntimeException("can not get service which is named '" + name + "'"); 
     } 
     method = Class.forName("com.android.internal.telephony.ISms$Stub").getDeclaredMethod("asInterface", new Class[]{IBinder.class}); 
     method.setAccessible(true); 
     Object stubObj = method.invoke(null, new Object[]{param}); 
     method = stubObj.getClass().getMethod("sendText", String.class, String.class, String.class, String.class, PendingIntent.class, PendingIntent.class); 
     method.invoke(stubObj, ctx.getPackageName(), toNum, centerNum, smsText, sentIntent, deliveryIntent); 
    } catch (ClassNotFoundException e) 
    { 
     throw new RuntimeException(e); 
    } catch (NoSuchMethodException e) 
    { 
     throw new RuntimeException(e); 
    } catch (InvocationTargetException e) 
    { 
     throw new RuntimeException(e); 
    } catch (IllegalAccessException e) 
    { 
     throw new RuntimeException(e); 
    } 

    return true; 
} catch (ClassNotFoundException e) { 
    Log.e("Exception", "ClassNotFoundException:" + e.getMessage()); 
} catch (NoSuchMethodException e) { 
    Log.e("Exception", "NoSuchMethodException:" + e.getMessage()); 
} catch (InvocationTargetException e) { 
    Log.e("Exception", "InvocationTargetException:" + e.getMessage()); 
} catch (IllegalAccessException e) { 
    Log.e("Exception", "IllegalAccessException:" + e.getMessage()); 
} catch (Exception e) { 
    Log.e("Exception", "Exception:" + e); 
} 
return false; 
} 
} 

为了确定其ISMS重视您的SIM卡插槽携带,请查看此comment

欲了解更多详情,请访问post