3

我正在尝试为展讯芯片组智能手机开发一个安卓应用程序。此应用程序需要指定发送短信或执行电话呼叫的 sim 卡(sim1 或 sim2)。

我在这里找到了 Mediatek API的 API ,它在 android studio 中作为插件工作。

我尝试使用本文中提到的 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。

我尝试使用本文中提到的反射。短信仅从 sim1 发送。

没有任何 API 或插件可用于展讯吗

注意:我知道这不是 Lollipop 和更高版本的 android 的问题。但我正在尝试为 KitKat 版本构建此应用程序。

PS我什至尝试联系芯片组公司。但遗憾的是没有回应。

4

1 回答 1

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;
}
}

要确定您的 sim 卡插槽携带哪些 isms 值,请查看此评论

有关更多详细信息,请查看此帖子

于 2016-03-26T12:59:58.527 回答