1, Listen to incoming SMS
1.1, Prepare manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.apache.sms">
<application>
<receiver class="SMSApp">
<intent-filter>
<action android:value="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
</manifest>
Remark: action android.provider.Telephony.SMS_RECEIVED is undocumented.
1.2, Parse SMS
package org.apache.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
public class SMSApp extends BroadcastReceiver
{
private static final String LOG_TAG = "SMSApp";
/* package */
static final String ACTION =
"android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
{
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
for (SmsMessage message : messages)
{
String strFrom = message.getDisplayOriginatingAddress();
String strMsg = message.getDisplayMessageBody();
}
}
}
}
}
Reference:
http://davanum.wordpress.com/2007/12/15/android-listen-for-incoming-sms-messages/
2 Listen to outgoing SMS (Remark: following code is not tested)
2.1 Register observer for outgoing SMS
class SMSHandler extends Handler
{
public void handleMessage(Message msg)
{
//Handle message
}
}
class SMSObserver extends ContentObserver
{
private Handle m_handle = null;
public SMSObserver(Handle handle)
{
super(handle);
m_handle = handle;
}
public void onChange(boolean bSelfChange)
{
super.onChange(bSelfChange);
//Send message o Activity
Message msg = new Message();
msg.obj = "xxxxxxxxxx";
m_handle.sendMessage(msg);
Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = this.getContentResolver().query(uriSMSURI, null, null,
null, null);
cur.moveToNext();
String protocol = cur.getString(cur.getColumnIndex("protocol"));
if(protocol == null)
onSMSSend();
else
onSMSReceive();
}
}
ContentResolver contentResolver = getContentResolver();
Handler handler = new SMSHandler();
ContentObserver m_SMSObserver = new SMSObserver(handler);
contentResolver.registerContentObserver(Uri.parse("content://sms/"),
true, m_SMSObserver); //Register to observe SMS in outbox,we can observe SMS in other location by changing Uri string, such as inbox, sent, draft, outbox, etc.)
2.2 Parse SMS
Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = this.getContentResolver().query(uriSMSURI, null, null,
null, null);
cur.moveToNext();
String protocol = cur.getString(cur.getColumnIndex("protocol"));
if(protocol == null)
onSMSSend();
else
onSMSReceive();
3 Read and Delete All SMS
/*
//Available Uri string
String strUriInbox = "content://sms/inbox";//SMS_INBOX:1
String strUriFailed = "content://sms/failed";//SMS_FAILED:2
String strUriQueued = "content://sms/queued";//SMS_QUEUED:3
String strUriSent = "content://sms/sent";//SMS_SENT:4
String strUriDraft = "content://sms/draft";//SMS_DRAFT:5
String strUriOutbox = "content://sms/outbox";//SMS_OUTBOX:6
String strUriUndelivered = "content://sms/undelivered";//SMS_UNDELIVERED
String strUriAll = "content://sms/all";//SMS_ALL
String strUriConversations = "content://sms/conversations";//you can delete one conversation by thread_id
String strUriAll = "content://sms"//you can delete one message by _id
*/
String strUriInbox = "content://sms/inbox";
Uri uriSms = Uri.parse(strUriInbox); //If you want to access all SMS, just replace the uri string to "content://sms/"
Cursor c = mContext.getContentResolver().query(uriSms, null, null, null, null);
while (c.moveToNext())
{
try
{
//Read the contents of the SMS;
for(int i; i < c.getColumnCount(); i++)
{
String strColumnName = c.getColumnName(i);
String strColumnValue = c.getString(i);
}
//Delete the SMS
String pid = c.getString(1); //Get thread id;
String uri = "content://sms/conversations/" + pid;
mContext.getContentResolver().delete(Uri.parse(uri), null, null);
}
catch (Exception e)
{
}
}
REMEBER: must request following permission
1) Read SMS
<uses-permssion android:name="android.permission.READ_SMS" />
2) Delete/Modify/Send SMS
<uses-permssion android:name="android.permission.WRITE_SMS" />
in AndroidManifest.xml
分享到:
相关推荐
OpenCV函数参考主要涵盖图像处理、结构分析、运动分析和对象跟踪、模式识别、照相机定标和三维重建等多个领域,这些是计算机视觉中的核心概念和技术。以下是对这些领域的详细说明: 1. **图像处理**: ...
"Ruby-Incoming"项目就是针对这种需求设计的一个库,它帮助开发者在基于Rack的应用程序中轻松地接收和处理电子邮件。 Rack是Ruby中的一个中间件框架,它定义了一种标准接口,使得各种Web服务器和框架之间能够无缝...
要插入一条新的短信,可以创建一个 ContentValues 对象并填充必要的字段,如`body`(短信内容)、`address`(发件人号码)和`type`(短信类型,如 incoming 或 outgoing),然后使用 ContentResolver 的 `insert()` ...
Install and run XMPP-FTW, connect to the server from the browser, and handle incoming/outgoing messages Connect to a multi-user chat room, send/receive stanzas, add a room password, join a protected ...
Install and run XMPP-FTW, connect to the server from the browser, and handle incoming/outgoing messages Connect to a multi-user chat room, send/receive stanzas, add a room password, join a protected ...
SAP财务模块紧要概述是对SAP系统中财务模块的总体概述,涵盖了财务模块中的各个组成部分,如会计清账、incoming and outgoing payments、payment differences、exchange rate differences等。 Clearing Open Items ...
Send TCP/IP messages to a destination IP address and port number, listen for incoming TCP/IP messages on a user-defined port, and echo received messages back to the source TCP/IP sender and receiver ...
Elastic optical networks (EON) based on optical ... The node structure incorporates a shared multicasting module, which performs reconfigurable selection of target incoming/outgoing superchannels/replica
The USB Host Controller incorporates...required for processing incoming and outgoing data, as well as legacy keyboard support for PS/2 keyboards connected to PS/2 keyboard controllers through Port 60/64.
5.3.2 Filtering Based on Content of Incoming SMS-MT 105 CHAPTER 6 Virtual SMSC Implementation and Transit Agreements 109 6.1 Business Model 109 6.2 Principle of the Virtual SMSC: Architecture and ...
这个问题其实在共识容器出现就存在了,现在PI NODE更新了0.4版,可以直接看到节点的运行状态,因此有些NODER才发现这个问题。关于这个问题,我之前在群里说过只有OUT没有IN代表是个瘸腿节点,并不能为其他节点提供...
将此文件保存为incoming_sms.php 如果$_GET 方法不起作用,则尝试$_REQUEST 方法。 创建此文件后,上传到您的 Web 服务器并将 URL 提供给您的 SMS 提供商。 示例代码已用于 SMSGatewayCenter.com 的传入 SMS 参数。...
Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET ...
通话记录的类型可以通过`CallLog.Calls.TYPE`字段获取,它可能的值有`CallLog.Calls.INCOMING_TYPE`, `CallLog.Calls.OUTGOING_TYPE`, 和 `CallLog.Calls.MISSED_TYPE`。 三、注意事项与最佳实践 1. 性能优化:...
- 网络指标如Incoming/Outgoing packets errors rate和rate用于检测网络通信的健康状况。 6. **性能测试与监控** - Load Testing期间,需持续监控上述各项指标,确保服务器在高负载下的稳定性。 - 对于Linux系统...
本翻译是直接根据 OpenCV Beta 4.0 版本的用户手册翻译的,原文件是:<opencv_directory>/doc/ref/opencvref_cv.htm, 可以从 SOURCEFORG 上面的 OpenCV 项目下载,也可以直接从 阿须数码 中下载:...
// 根据type判断通话类型(如:incoming=1,outgoing=2,missed=3) // 打印通话记录信息 Log.d("Call", "Number: " + number + ", Type: " + type + ", Duration: " + duration + "s, Date: " + date); } ...
在 Sailfish 的终端应用程序中执行:./mobcount.sh 其中: mode = c (call) or s (sms) io = i (incoming), o (outgoing) t1 = start time (unix format) t2 = end time (unix format) 有关更多信息,请参阅源代码...
// Helper function to convert call type integer to string private String getCallType(int type) { switch (type) { case CallLog.Calls.INCOMING_TYPE: return "Incoming"; case CallLog.Calls.OUTGOING_...
.NET Reflector是一个类浏览器和反编译器,利用反射机制来分析程序集,以展示程序集中各种类型及其...你可以从下面的地址找到一个.NET Reflector Add-Ins的列表:http://www.aisto.com/Incoming/Reflector/AddIns/。