老问题,新总结,获取本机号码

1. http://www.ityoudao.com/Web/Android_657_2001.html

本文中所讲的需求简单,明了,我说的简单指的是只有一个需求,不复要,不复合,就是一个,取得本机号码,请你看下面这代码

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// 获取手机号码

String phoneId = tm.getLine1Number();
Log.i(phoneId,phoneId);

你猜会怎么样,取不到!奇怪吧,神奇吧~~~怎么的的,你就是没有办法取得本机号码,这是为什么呢,有何良策,我心里在想啊,肿么办!

我静心一想解决问题得找到问题所在,不然无从下手...经我google/baidu,找到了基本的原因和曲线救国之解决方法,现逻列如后:
第一点:造成原因
能否取得手机号码依赖于运营商是如何制作SIM卡的,所以有的可以取出,有的则不行。看吧,这不全是你的错,哈哈~~~
第二点:解决方案
给10086发个短信就行了,然后获取发件箱中的发件人号码...反正给10086发短信或者打电话是免费的 ,但是你得注意了
1、获取发件箱中的发件人号码后你得把发件箱中记录删除;
2、就是你还要拦截10086给你回复的短信,不然会有个notification显示在屏幕上方,提示10086发来个短信,让你查看;
这些都是为了取得本机号码的任务下,但同时又提高了用户的体验度...明白吗?

===================================================
这个可能才是终极的解决办法吧。。。。呵呵



public void sendTextMessage (String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)

Since: API Level 4
Send a text based SMS.

Parameters
destinationAddress the address to send the message to
scAddress is the service center address or null to use the current default SMSC
text the body of the message to send
sentIntent if not NULL this PendingIntent is broadcast when the message is successfully sent, or failed. The result code will be Activity.RESULT_OK for success, or one of these errors:
RESULT_ERROR_GENERIC_FAILURE
RESULT_ERROR_RADIO_OFF
RESULT_ERROR_NULL_PDU
For RESULT_ERROR_GENERIC_FAILURE the sentIntent may include the extra "errorCode" containing a radio technology specific value, generally only useful for troubleshooting.
The per-application based SMS control checks sentIntent. If sentIntent is NULL the caller will be checked against all unknown applications, which cause smaller number of SMS to be sent in checking period.
deliveryIntent if not NULL this PendingIntent is broadcast when the message is delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu").
Throws
IllegalArgumentException if destinationAddress or text are empty

http://www.open-open.com/lib/view/open1332139318999.html
http://www.2cto.com/kf/201203/121892.html


这篇文章很有参考意义
http://jessical08.iteye.com/blog/877138
http://blog.csdn.net/sodino/article/details/5871537
全国短信中心号码 
http://zdm2008.blog.163.com/blog/static/20491545201062210921272/

Android中怎样取本机的手机号码
http://www.cppblog.com/fwxjj/archive/2011/01/27/139433.html

android中短信协议与字段
http://blog.csdn.net/tianqixin/article/details/6705899
Android短信数据字段
http://xmj101.iteye.com/blog/1382431


----------------------------------------------------------
eoe的问题:
http://www.eoeandroid.com/thread-181202-1-1.html
android 短信字段 貌似没有收件人号码这个字段。。。。。貌似短信获取本机号,也不是很现实,也只有让用户自行输入了。。。。


http://edison-cool911.iteye.com/blog/751644
这个总结的非常好。。。不错

猜你喜欢

转载自macleo.iteye.com/blog/1608311
今日推荐