我正在寻找获取发送短信的应用程序的进程ID的方法。我可以通过OutboundMessageListener获取发送消息的内容,但我不知道如何获取进程ID。
这是我的尝试:
MessageConnection _mc = (MessageConnection) Connector.open("sms://:0");
_mc.setMessageListener(new OutboundSMSListener());
private static final class OutboundSMSListener implements OutboundMessageListener
{
public void notifyIncomingMessage(MessageConnection messageconnection)
{
System.out.println("Incoming message received ");
}
public void notifyOutgoingMessage(Message message)
{
System.out.println("------------------------\n\n\n\n\n");
System.out.println("Message send: " + message);
}
}
有没有办法做到这一点?
答案 0 :(得分:0)
应用程序发送短信是BlackBerry设备的本机应用程序,它是否位于前台?
要获取前台应用程序的进程ID,您可以使用以下代码:
private int getForegroungProcessID() {
return ApplicationManager.getApplicationManager().getForegroundProcessId();
}
private String getAppNameByProcessId(int id) {
String result = null;
ApplicationManager appManager = ApplicationManager.getApplicationManager();
ApplicationDescriptor appDes[] = appManager.getVisibleApplications();
for (int i = 0; i < appDes.length; i++) {
if (appManager.getProcessId(appDes[i]) == id) {
result = appDes[i].getModuleName();
//// here check the app name...is it a messaging app ///
break;
}
}
return result;
}