Q: How do I retrieve the phone number from my midlet?
You would have to use the JSR 253 - Mobile Telephony API which allows you to have a fairly good set of call-related funcionality, so it's possible that this API will also provide a way to let you know what's your phones's number. No Nokia devices currently support JSR 253.
There are some possible workarounds:
- When the user first downloads the application, have a server-side app such as a Java servlet or PHP script that retrieves the phone number from the HTTP header, and set it as a property in a dynamically-generated JAD file. This way, when your midlet is running, it can check the phone number using getAppProperty() method from MIDlet class. This approach will only work if the device is accessing the server-side application using a WAP access point, however. This happens because in this type of access point, an HTTP header containing the MSISDN (phone number) is added to the HTTP request that will be forwarded to your application, so you can retrieve it.
- If the target handset supports the Wireless Messaging API, you can have your application register an SMS connection, using PushRegistry, with a non-standard port. When the user first starts the application, generate some random data and send it to the phone number the user will input on a text field. If the phone number is correct, than you’ll receive the message in a few seconds on the connection you've registered. You can then check the data to see if it matches the data you generated earlier, and if it does, get the sender phone number using
Code:
Message.getAddress()
- If you are using an S60 device, you can write a Symbian C++ application that retrieves the phone number and opens a server socket on 127.0.0.1. The midlet then connects to this localhost socket and retrieves that information. There are some drawbacks to this approach: Your C++ application has to be started on boot, the method used to retrieve the phone number is not portable (if you’re getting only the IMEI code, not the phone number, then it's portable); third, it depends on a C++ application, which greatly increases complexity by itself. There's a project called [URL ="http://www.midpjni.com/"]MIDP JNI[/url] that uses this "bridge" approach to bring native functionality to midlets, so you can retrieve information that otherwise would be only available to C++ applications, such as network and device properties.
我就简单的说下原文的意思吧,不想看英文的朋友参考一下:
解决方法有:
1.jsr 253。可以通过此jsr,获取与手机电话有关的信息,但nokia还没有任何一款手机支持此扩展包(截至2007-02-06, 16:16 )。
2.截取http报头。这种方法在前两年(05年左右),仍是可行的,但移动后来更改了报文结构,屏蔽了手机号字段。(它要拿手机号来卖钱,凡是跟手机号挂钩的,必须要跟它合作,也就是给钱他)
3.通过我们被安装的软件,发送短信到指定地址(本机到它机,本机到本机),在收到短信的平台,可以通过message的功能函数,来获取发送此短信的手机号码。(参考jsr 205规范,里面有短信的发送和截获)
4.对于symbian程序员,有其他方法。(不在本文讨论之内,这里是j2me板块)