2016-03-03 19 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

相關問題