Monitor MMS
来源:互联网 发布:网络佳句赏析最经典 编辑:程序博客网 时间:2024/05/21 17:15
The mms/sms are stored in SQLite file
/data/data/com.android.providers.telephony/databases/mmssms.db
/data/data/com.android.providers.telephony/app_parts/*
mmssms.db srotes the sms and mms information, and the files under app_parts stores the files attached in MMS.
Other application has no permission to access that database file, we only can read mms/sms throung content provider.
Sample code:
Cursor curPdu = getContentResolver().query(Uri.parse("content://mms"), null, null, null, null);
int id = curPdu.getInt(curPdu.getColumnIndex("_id"));
int thread_id = curPdu.getInt(curPdu.getColumnIndex("thread_id"));
String subject = curPdu.getString(curPdu.getColumnIndex("sub");
int date = curPdu.getInt(curPdu.getColumnIndex("date"));
//Delete mms
getContentResolver().delete(Uri.parse("content://mms/" + Integer.toString(id)));
String selectionAddr = new String("msg_id='" + Integer.toString(id) + "'");
Uri uriAddr = Uri.parse("content://mms/" + curPdu.getString(curPdu.getColumnIndex("_id")) + "/addr"); //use provider 'content://mms/#/addr' to get address
Cursor curAddr = getContentResolver().query(Uri.parse(uriAddr, null, selectionAddr, null, null);
String contact_id = curAddr.getString(curAddr.getColumnIndex("contact_id"));
String address = curAddr.getString(curAddr.getColumnIndex("address"));
String selectionPart = new String("mid='" + Integer.toString(id) + "'");
Cursor curPart = getContentResolver().query(Uri.parse("content://mms/part"), null, selectionPart, null, null);
/*
//You can also use following code
Cursor curPart = getContentResolver().query(Uri.parse("content://mms/" + Integer.toString(id) + "/part"), null,null , null, null);
*/
while(curPart.moveToNext())
{
String type = curPart.getString(curPart.getColumnIndex("ct")); //content type
String attachmentpath = curPart.getString(curPart.getColumnIndex("_data"));
String cid = curPart.getString(curPart.getColumnIndex("cid"));
if (cid.euqals("<text_0>") //Current row stores MMS body
{
String body = curPart.getString(curPart.getColumnIndex("text"));
}
else if (!attachmentpath.euqals(null)) //Current row stores MMS attachment, following code is used to read the attachment file
{
int _partID = curPart.getInt(curPart.getColumnIndex("_id"));
String partID = String.valueOf(_partID);
Uri partURI = Uri.parse("content://mms/part/" + partID);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); //This is attachment
InputStream is = null;
try
{
is = getContentResolver().openInputStream(partURI);
byte[] buffer = new byte[256];
int len = is.read(buffer);
while (len >= 0)
{
baos.write(buffer, 0, len);
len = is.read(buffer);
}
}
catch (IOException e)
{
}
finally
{
if (is != null)
{
try
{
is.close();
} catch (IOException e) {}
}
}
}
}
if (curPart.moveToFirst())
do
{
}
Declare permission
<uses-permission android:name="android.permission.READ_SMS" />
http://dislab.hufs.ac.kr/wiki/Android/Native_Providers
- Monitor MMS
- [Android] Monitor MMS
- MMS
- MMS
- MMS
- mms
- mms
- MMS
- monitor
- Monitor
- Monitor
- Monitor
- monitor
- Monitor
- MMS - 什么是MMS?
- diff mms/setup ../mms/mms/setup
- MMS封装
- mms地址
- 基于QT C++的网络缓冲区设计(一)——概括
- QQ与360之争
- 微软Silverlight团队关于PDC会议发表官方补充声明(风云翻译版)
- C#中压缩工具整理之一 : DotNetZipLib
- 这是一个好地方
- Monitor MMS
- 白雪歌送武判官归京
- ;simple calculagraph made by fanpei
- c# socket编程之ftp
- char、varchar、nchar、nvarchar
- linux下普通账户执行sudo命令
- 一个用于启动/停止特定服务的托盘程序——VS2008实现
- CString与其他数据类型的转换
- 多线程调试--日志--1