我的工作给我分配了一份工作来研究在技术上是否可行
Launch Browser with specific URL from SIM Application Toolkit using Java Card 2.2.1.
我尝试使用 sim.toolkit 库中的 ProactiveHandler。启动浏览器的确切代码看起来像这样
我的测试小程序只在屏幕上显示菜单项,当我单击它时,它应该会启动浏览器。编辑更完整的源代码:
我处理事件的部分
private final byte[] GOOGLE = {(byte) 'h', (byte) 't', (byte) 't', (byte) 'p', (byte) ':', (byte) '/', (byte) '/', (byte) 'w', (byte) 'w', (byte) 'w', (byte) '.', (byte) 'g', (byte) 'o', (byte) 'o', (byte) 'g', (byte) 'l', (byte) 'e', (byte) '.', (byte) 'c', (byte) 'o', (byte) 'm'};
public void processToolkit(byte event) throws ToolkitException {
switch (event) {
case EVENT_MENU_SELECTION:
displayText(TEXT, (byte) 0, (byte) TEXT.length);
sendToBrowser(GOOGLE);
break;
case EVENT_FORMATTED_SMS_PP_ENV:
handleSMSComand();
break;
default:
return;
}
}
我这样做是为了当我点击菜单项时,它会调用我的 sendToBrowser 函数。 displayText 函数只是在屏幕上显示文本。我的完整功能代码是这样的:
private byte sendToBrowser(byte[] data) throws ToolkitException {
if (MEProfile.check(PROFILE_LAUNCH_BROWSER)) {
try {
ProactiveHandler ph = ProactiveHandler.getTheHandler();
displayText(new byte[]{(byte) 'H', (byte) 'S'}, (byte) 0, (byte) 2);
try {
ph.init(PRO_CMD_LAUNCH_BROWSER, (byte) 0x00, DEV_ID_ME);
displayText(new byte[]{(byte) 'C', (byte) 'S'}, (byte) 0, (byte) 2);
try {
ph.appendTLV(TAG_URL, data, (short) 0, (short) data.length);
displayText(new byte[]{(byte) 'T', (byte) 'S'}, (byte) 0, (byte) 2);
try {
ph.send();
return displayText(new byte[]{(byte) 'S', (byte) 'S'}, (byte) 0, (byte) 2);
} catch (Exception te){
return displayText(new byte[]{(byte) 'S'}, (byte) 0, (byte) 1);
}
} catch (Exception te) {
return displayText(new byte[]{(byte) 'T'}, (byte) 0, (byte) 1);
}
} catch (Exception te) {
return displayText(new byte[]{(byte) 'C'}, (byte) 0, (byte) 1);
}
} catch (Exception te) {
return displayText(new byte[]{(byte) 'H'}, (byte) 0, (byte) 1);
}
} else {
return displayText(new byte[]{(byte) 'M'}, (byte) 0, (byte) 1);
}
}
代码在非 iOS 设备上运行,但不会启动浏览器。它不会抛出任何错误和 ph.send();即使未启动浏览器也能成功运行。所以我猜这种方法不再适用于最新的手机?我的测试手机都是高端安卓设备。
是否有任何其他方法可以启动带有 Java Card 2.2.1 的浏览器?如果不是,我会报告说这在技术上是不可能的,而且之前的方法在新手机上不起作用。
这是我的 displayText 函数,但它可能无关紧要
private byte displayText(byte[] messageBuffer, short offset, short length) {
byte result = RES_ERROR_CMD_DATA_NOT_UNDERSTOOD;
try {
if (length == 0) {
return 0;
}
ProactiveHandler ph = ProactiveHandler.getTheHandler();
ph.initDisplayText((byte) 0x81, DCS_8_BIT_DATA, messageBuffer,
offset, length);
result = ph.send();
} catch (Exception te) {
result = RES_ERROR_CMD_DATA_NOT_UNDERSTOOD;
}
return result;
}
最佳答案
当我们对我们的 SIM 小程序进行测试以使用相关的主动命令(LAUNCH BROWSER
)在终端上触发启动浏览器时,我们意识到虽然终端返回命令的肯定响应,但浏览器已经没有在屏幕上弹出。此功能对终端供应商有依赖性,尽管返回了 ACK,但某些手机仍不支持。
关于java - 如何在 Java Card 中使用 Sim Toolkit 的 url 启动浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49398542/