android 短信:电信运营商给你的号码可能是+86开头

news/2025/3/16 11:36:55/


源码中的注意点即:电信运营商给你的号码可能是+86开头的,这个时候去与通讯录中库中的数据匹配,如果不做模糊匹配是不行的,而一些号码更是有‘-’在数字中间。

/*** This service essentially plays the role of a "worker thread", allowing us to* store incoming messages to the database, update notifications, etc. without* blocking the main thread that SmsReceiver runs on.*/
public class SmsReceiverService extends Service

	private void handleSmsReceived(Intent intent) {SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);Log.i(TAG, "------ msgs.length() -------" + msgs.length);Uri messageUri = insertMessage(this, msgs);if (messageUri != null) {
//			MessagingNotification.updateNewMessageIndicator(this, true);MessagingNotification.updateNewMessageIndicatorandNotifyLac(this, true);}voicePrompt(msgs);}

private synchronized void voicePrompt(SmsMessage[] msgs){Log.d(TAG, "Coming SMS, suggesting the need for reading");strRead = new StringBuffer();SmsMessage msg = msgs[0];if (msg != null){String address = msg.getOriginatingAddress();Log.d(TAG, "======Phone Number:" + address + "======" );if (!TextUtils.isEmpty(address)){forEachContact(SmsReceiverService.this);		String name = getContactsNameByNumber(SmsReceiverService.this, address);if (!TextUtils.isEmpty(name)){strRead.append(name);}else{String prefix = "+86";int index = address.indexOf(prefix);if (index != -1){address =   address.substring(index + prefix.length()  )  ;}String nameAgain = getContactsNameByNumber(SmsReceiverService.this, address);if (!TextUtils.isEmpty(nameAgain)){strRead.append(nameAgain);}else {address = address.replace("+86", "");String fuzzyMatchingName = getContactNumber(SmsReceiverService.this,address);if(!TextUtils.isEmpty(fuzzyMatchingName)){strRead.append(fuzzyMatchingName);}else{strRead.append(getResources().getString(R.string.phone_num)  + "[r1][n1]"+ address + "[r0][n0]");}}}}else {Log.d(TAG, "address is empty");}}msgget = Message.obtain();msgget.what = 1;handler.sendMessageDelayed(msgget, 1000);}

	private synchronized String getContactsNameByNumber(Context context, String number){Log.d(TAG, "look for contact name by number");ContentResolver cr = context.getContentResolver();Cursor cursor = cr.query(Contacts.Phones.CONTENT_URI, new String[] { Contacts.Phones.NAME }, Contacts.Phones.NUMBER + " = ?",new String[] { number }, null);if (cursor != null){int count = cursor.getCount();if (count > 0){if (cursor.moveToFirst()){do{String name = cursor.getString(cursor.getColumnIndex(Contacts.Phones.NAME));Log.d(TAG, "find name : " + name );if (name != null){return name;}}while (cursor.moveToNext());}}}return null;}


http://www.ppmy.cn/news/445511.html

相关文章

中国移动、中国联通、中国电信号码网段大全

中国移动134,135,136,137,138,139, 150,151,152,154,157,158,159 187, 188(TD-SCDMA), 147 中国联通130&a…

(转)路由器WAN口IP显示为10、100、172开头,网络被电信联通等运营商做了NAT转发

转自:http://www.ekingcn.com/school/pcfaq_1658_202.html 1、表现形式: 路由器拨号获得的公网IP变成了一个以100开头的IP(或者是10、172开头),而打开www.ip138.com查询却又是另外一个IP,将100开头的这个I…

HG2821T-U电信光猫修改SSID去掉ChinaNet

大家使用天翼的光猫有一个痛点,就是WIFI的名字是ChinaNet-XXX,这里我们肯定是我的光猫我做主! 于是2023年1月2日,我花了近半天的时间去攻克这个问题。 我尝试过以下方法: 1.直接登录进行修改成自己的MyWIFI(为例),保存后依然是原来的那样。 2.拿到超级管理员账号,保存后提示 …

课程17:菜单管理功能实现

🚀前言 本文是《.Net Core从零学习搭建权限管理系统》教程专栏的课程(点击链接,跳转到专栏主页,欢迎订阅,持续更新…) 专栏介绍:以实战为线索,基于.Net 7 + REST + Vue、前后端分离,不依赖任何第三方框架,从零一步一步讲解权限管理系统搭建。 专栏适用于人群:We…

Python 循环与判断(详解)

❄️作者介绍:奇妙的大歪❄️ 🎀个人名言:但行前路,不负韶华!🎀 🐽个人简介:云计算网络运维专业人员🐽 前言 在Python中,循环语句有两个,一个是fo…

OPC是什么及OPC简介

opc既不是硬件也不是软件。OPC是一种通讯规范,OPC基金会组织规定的一套规范,按照这个规范去把程序写出来,包括一个OPC服务器程序和一个OPC客户端程序,只要是按规范写的,不管是谁写的,就能保证OPC服务器能被…

什么是OOP?

什么是OOP? OOP即面向对象程序设计,全bai称为Object Oriented Programming,是一种du计算机编程架构。其zhi本质是以建立模型体现出来的抽象dao思维过程和面向对象的方法,模型是用来反映现实世界中事物特征的。 面向对象程序设计…

综合设计一个OPPE主页--页面的售后服务

分析样式: 一共六块(整体可以使用列表) 里面的每一小块实际上也是一个列表; 实现效果: 有一个父子样式的跟随 子样式的背景图片的样式跟随父样式一同变化----鼠标触发 实现父子样式一起变化 但是变化的内容不同 #alt…