message

1.SmsInfo

public class SmsInfo {

private int id;

private long data;

private int type;

private String body;

private String address;

public SmsInfo(long data, int type, String body, String address){

this.data=data;

this.address=address;

this.type=type;

this.body=body;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public long getData() {

return data;

}

public void setData(long data) {

this.data = data;

}

public int getType() {

return type;

}

public void setType(int type) {

this.type = type;

}

public String getBody() {

return body;

}

public void setBody(String body) {

this.body = body;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

}

2.SmsUtils

public class SmsUtils {

public static void backUpSms(List smsInfoList,Context context) throws IOException {

//创建序列化器serializer

XmlSerializer serializer= Xml.newSerializer();

//获取sd卡根目录的路径

File file=new File(Environment.getExternalStorageDirectory(),"sms.xml");

//获得输出流

FileOutputStream os=new FileOutputStream(file);

//设置编码方式

serializer.setOutput(os,"utf-8");

//写入xml文件标识

serializer.startDocument("utf-8",true);

serializer.startTag(null,"smss");

for(SmsInfo info:smsInfoList){

serializer.startTag(null,"sms");

serializer.attribute(null,"id",info.getId()+"");

serializer.startTag(null,"body");

serializer.text(info.getBody());

serializer.endTag(null,"body");

serializer.startTag(null,"type");

serializer.text(info.getType()+"");

serializer.endTag(null,"type");

serializer.startTag(null,"address");

serializer.text(info.getAddress());

serializer.endTag(null,"address");

serializer.startTag(null,"date");

serializer.text(info.getData()+"");

serializer.endTag(null,"date");

serializer.endTag(null,"sms");

}

serializer.endTag(null,"smss");

serializer.endDocument();

Toast.makeText(context,"成功",Toast.LENGTH_LONG).show();

}

}

3Duanxin.Activity

public class DuanxinActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_duanxin);

}

public void onclick(View view) throws IOException {

//content://sms查新系统所有短信的uri

Uri uri= Uri.parse("content://sms");

//获得 访问内容提供者

ContentResolver contentResolver=getContentResolver();

//通过contentResolver查询数据

Cursor cursor=contentResolver.query(uri,new String[]{"address","date","type","body"},null,null,null);

List smsInfoList=new ArrayList();

//cursor.moveToNext()移动到下一行

while (cursor.moveToNext()){

String address=cursor.getString(0);

long date=cursor.getLong(1);

int type=cursor.getType(2);

String body=cursor.getString(3);

SmsInfo smsInfo=new SmsInfo(date,type,body,address);

smsInfoList.add(smsInfo);

}

//读取数据结束

cursor.close();

//备份

SmsUtils.backUpSms(smsInfoList,this);

}

}

4.布局文件

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="com.example.believer.gougoude.DuanxinActivity">

android:layout_centerVertical="true"

android:layout_centerHorizontal="true"

android:onClick="onclick"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="获取"/>

5.Android

 

 

时间: 2024-11-04 04:24:07

message的相关文章

Handler和Message详解

Android开发中Handler的经典总结 当应用程序启动时,Android首先会开启一个主线程(也就是UI线程),主线程为管理界面中的UI控件,进行事件分发. 一.Handler的定义: 主要接受子线程发送的数据, 并用此数据配合主线程更新UI. 解释:当应用程序启动时,Android首先会开启一个主线程 (也就是UI线程) , 主线程为管理界面中的UI控件, 进行事件分发, 比如说, 你要是点击一个 Button ,Android会分发事件到Button上,来响应你的操作.  如果此时需要

“intel_rapl: no valid rapl domains” message upon boot blacklist.conf -1

"intel_rapl: no valid rapl domains" message upon boot I install fresh Ubuntu 14. 04 server under ESXI 5.1.0.During my installation I did not get any erorrs or strange things. My problem is when I boot machine at console screen I get messages lik

hdu 4661 Message Passing(树形DP&组合数学)

Message Passing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1187    Accepted Submission(s): 423 Problem Description There are n people numbered from 1 to n. Each people have a unique mes

HDU 4300 Clairewd’s message

Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that each letter of these messages would be transfered to a

Long Long Message(后缀数组)

Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 30427   Accepted: 12337 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days

解决LLDB模式下出现message sent to deallocated instance错误

本文在源文的基础上做整理:http://www.devdiv.com/home.php?mod=space&uid=50901&do=blog&id=50856 Xcode版本7.1 IOS版本9.1 公司之前开发的一个APP,在使用环境中IOS版本升级到9.0以后,某个操作会导致程序闪退. Xcode代码中提示错误: 1 Thread 1: Program received signal:"EXC_BAD_ACCESS" 这样的提示意味着对已经释放的对象发送消

webapi <Message>已拒绝为此请求授权。</Message>

原有的调用base.OnAuthorization(actionContext); 换成下面这个 /// <summary> /// 鉴权 /// </summary> /// <param name="actionContext"></param> public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContex

[Angular] Scrolling the Message List To the Bottom Automatically Using OnChanges

Let's say the message list can Input (messages) from parent component, and what we want to do is when there are new message, we will scroll message list to the bottom to show the lastest message. import {Component, Input, ViewChild, OnChanges, Simple

Android Message Handling Mechanism

转自:http://solarex.github.io/blog/2015/09/22/android-message-handling-mechanism/ Android is a message driven, message driven several elements: The message says: Message Message queue: MessageQueue The news cycle, remove the message processing for circ

JAVA多线程(九)模式-Thread Per Message

Thread Per Message 请求的频率高于处理速度,由线程池平衡请求速度和处理速度. 适用环境 不需要返回数据,处理顺序无关的场景. 样例 每一次请求都由线程池中一个线程处理. 服务端 package ThreadPerMessage; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Host{ private ExecutorService