SMS管理Word文件下载.docx

上传人:b****4 文档编号:8214944 上传时间:2023-05-10 格式:DOCX 页数:17 大小:57.25KB
下载 相关 举报
SMS管理Word文件下载.docx_第1页
第1页 / 共17页
SMS管理Word文件下载.docx_第2页
第2页 / 共17页
SMS管理Word文件下载.docx_第3页
第3页 / 共17页
SMS管理Word文件下载.docx_第4页
第4页 / 共17页
SMS管理Word文件下载.docx_第5页
第5页 / 共17页
SMS管理Word文件下载.docx_第6页
第6页 / 共17页
SMS管理Word文件下载.docx_第7页
第7页 / 共17页
SMS管理Word文件下载.docx_第8页
第8页 / 共17页
SMS管理Word文件下载.docx_第9页
第9页 / 共17页
SMS管理Word文件下载.docx_第10页
第10页 / 共17页
SMS管理Word文件下载.docx_第11页
第11页 / 共17页
SMS管理Word文件下载.docx_第12页
第12页 / 共17页
SMS管理Word文件下载.docx_第13页
第13页 / 共17页
SMS管理Word文件下载.docx_第14页
第14页 / 共17页
SMS管理Word文件下载.docx_第15页
第15页 / 共17页
SMS管理Word文件下载.docx_第16页
第16页 / 共17页
SMS管理Word文件下载.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

SMS管理Word文件下载.docx

《SMS管理Word文件下载.docx》由会员分享,可在线阅读,更多相关《SMS管理Word文件下载.docx(17页珍藏版)》请在冰点文库上搜索。

SMS管理Word文件下载.docx

1.定义SMSObserver用于监听目标并通过Handle通知注册方

publicclassSMSObserverextendsContentObserver{

publicfinalstaticintSMS_CHANGE=0;

Handlerhandle;

publicSMSObserver(Handlerh){

super(h);

//TODOAuto-generatedconstructorstub

handle=h;

}

publicvoidonChange(booleanselfChange){

//TODOAuto-generatedmethodstub

super.onChange(selfChange);

//notifySMSInbox&

SMSSent

handle.sendEmptyMessage(SMS_CHANGE);

}

2.定义注册方:

SMSInbox鉴于SMSSent与其原理类似故打算以SMSInbox为例 

>

2.1.显示当前所有收信箱并与ListView适配

lv=(ListView)findViewById(R.id.list);

cursor=getContentResolver().query(Uri.parse("

//sms/inbox"

),null,null,null,null);

adapter=newItemAdapter(this);

lv.setAdapter(adapter);

2.2.定义Handle用于接受变动并注册与ContentObserve当接到通知后查询目标Uri并刷新显示

handler=newHandler(){

publicvoidhandleMessage(Messagemsg){

if(msg.what==SMSObserver.SMS_CHANGE){

cursor=getContentResolver().query(Uri.parse("

adapter.notifyDataSetChanged();

}

}

};

sObserver=newSMSObserver(handler);

this.getContentResolver().registerContentObserver(Uri.parse("

//sms"

),true,sObserver);

2.3. 

SMSInbox仅用于显示收信箱 

故定义SMSDetailsextendsActivity用于详细显示sms信息 

-2.3.1.定义布局:

details.xml

<

?

xmlversion="

1.0"

encoding="

utf-8"

LinearLayoutxmlns:

android="

android:

orientation="

vertical"

layout_width="

fill_parent"

layout_height="

>

TextView

id="

@+id/detailsNumber"

wrap_content"

/>

@+id/detailsBody"

200dip"

horizontal"

300dip"

Button

@+id/detailsReply"

100dip"

layout_gravity="

left"

text="

回复"

@+id/detailsOK"

right"

确定"

/LinearLayout>

-2.3.2.其中2个TextView分别显示信息地址和正文2个Button一个用于关闭当前窗口一个用于短信回复且自动填充收信人地址

publicclassSMSDetailsextendsActivity{

TextViewtextNumber,textBody;

ButtonbtnOK,btnReply;

OnClickListenercl;

Stringaddress,body;

/**Calledwhentheactivityisfirstcreated.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.details);

textNumber=(TextView)findViewById(R.id.detailsNumber);

textBody=(TextView)findViewById(R.id.detailsBody);

btnReply=(Button)findViewById(R.id.detailsReply);

btnOK=(Button)findViewById(R.id.detailsOK);

Intenti=this.getIntent();

Bundlebundle=i.getExtras();

address=bundle.getString("

address"

);

body=bundle.getString("

body"

textNumber.setText("

from:

"

+address);

textBody.setText("

messagebody:

\n"

+body);

cl=newOnClickListener(){

@Override

publicvoidonClick(Viewarg0){

//TODOAuto-generatedmethodstub

switch(arg0.getId()){

caseR.id.detailsReply:

sendGoNativeNew(address);

break;

caseR.id.detailsOK:

sendBack();

}

btnReply.setOnClickListener(cl);

btnOK.setOnClickListener(cl);

publicvoidsendGoNativeNew(Stringaddress){

//nativesendsmsapp

IntentsendIntent=newIntent(Intent.ACTION_SENDTO,Uri.parse("

sms:

//"

));

//autofill"

sendIntent.putExtra("

address);

startActivity(sendIntent);

publicvoidsendBack(){

Intenti=newIntent();

this.setResult(RESULT_OK,i);

this.finish();

-2.3.3. 

点击SMSInbox某项跳转到SMSDetails

lv.setOnItemClickListener(newOnItemClickListener(){

publicvoidonItemClick(AdapterView<

arg0,Viewarg1,intarg2,

longarg3){

cursor.moveToPosition(arg2);

Stringbody=cursor.getString(cursor.getColumnIndexOrThrow("

)).toString();

Stringaddress=cursor.getString(cursor.getColumnIndexOrThrow("

Bundleb=newBundle();

b.putString("

body);

Intentintent=newIntent(SMSInbox.this,SMSDetails.class);

intent.putExtras(b);

startActivity(intent);

});

-2.3.4.其中 

item.xml用于定义子项布局

ImageView

@+id/body"

@+id/num"

paddingLeft="

5dip"

10dip"

3.鉴于SMSSent与SMSInbox大同小异故不再细说仅补上代码

publicclassSMSSentextendsActivity{

ListViewlv;

Cursorcursor;

ItemAdapteradapter;

SMSObserversObserver;

Handlerhandler;

setContentView(R.layout.list);

setTitle(R.string.sent);

lv=(ListView)findViewById(R.id.list);

//sms/sent"

lv.setOnItemClickListener(newOnItemClickListener(){

Intentintent=newIntent(SMSSent.this,SMSDetails.class);

//registerSMSObserve

handler=newHandler(){

publicclassItemAdapterextendsBaseAdapter{

Activityactivity;

publicItemAdapter(Activitya){

activity=a;

@Override

publicintgetCount(){

//TODOAuto-generatedmethodstub

returncursor.getCount();

publicObjectgetItem(intarg0){

returncursor.getString(arg0);

publiclonggetItemId(intarg0){

returnarg0;

publicViewgetView(intarg0,Viewarg1,ViewGrouparg2){

returncomposeItem(arg0);

privateViewcomposeItem(intposition){

cursor.moveToPosition(position);

Stringbody=cursor.getString(cursor.getColumnIndexOrThrow("

Stringnumber=cursor.getString(cursor.getColumnIndexOrThrow("

LinearLayoutitem=(LinearLayout)activity.getLayoutInflater().inflate(R.layout.item,null);

LinearLayoutl1=(LinearLayout)item.getChildAt(0);

TextViewtbody=(TextView)item.getChildAt

(1);

if(tbody!

=null){

tbody.setText(body);

TextViewtnum=(TextView)l1.getChildAt

(1);

if(tnum!

tnum.setText(number);

ImageViewimage=(ImageView)l1.getChildAt(0);

image.setImageResource(R.drawable.message);

returnitem;

4.emulator运行截图

4.1. 

SMSInbox:

-4.1.1.通过telnetlocalhost5554登录emulator 

通过smssend123helloto123模拟发送短信

-4.1.2.短信发送记录为:

AndroidConsole:

type'

help'

foralistofcommands

OK

smssend12ds

smssend23hito23

smssend34iamgriddinshi

-4.1.3.SMSInbox:

4.2.SMSSent

-4.2.1.已发短信记录:

-4.2.2.SMSSent:

5.未解决问题:

5.1.ContentObserver只能监听content:

//sms 

而不支持content:

//sms/sent 

个人猜测是因为:

android在写sms数据库insert(...)没有通过ContentResolver通知content:

//sms/sent所致即:

没有以下代码:

getContext().getContentResolver().notifyChange(no

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2