Android短信开发之调用.doc_第1页
Android短信开发之调用.doc_第2页
Android短信开发之调用.doc_第3页
Android短信开发之调用.doc_第4页
Android短信开发之调用.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

打电话和发短信可以说是最核心的应用了,本文就来阐述它的调用方法。可以分为直接调用-直接电话或短信发出,已经间接调用-进入拨号或短信撰写页面,等待用户确认内容后由用户发出.先看代码效果截图: 编写主界面Activity,创建类CallAndSms作为默认启动页package jtapp.callandsms;import java.util.List;import android.app.Activity;import android.content.Intent;import .Uri;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class CallAndSms extends Activity /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); setComponent(); private void setComponent() Button bt1 = (Button) findViewById(R.id.Button01); bt1.setOnClickListener(new OnClickListener() Override public void onClick(View v) Intent intent = new Intent( Intent.ACTION_CALL, Uri.parse(tel:10010); startActivity(intent); ); Button bt2 = (Button) findViewById(R.id.Button02); bt2.setOnClickListener(new OnClickListener() Override public void onClick(View v) String smsContent = 102; / note: SMS must be divided before being sent SmsManager sms = SmsManager.getDefault(); List texts = sms.divideMessage(smsContent); for (String text : texts) sms.sendTextMessage(10010, null, text, null, null); / note: not checked success or failure yet Toast.makeText( CallAndSms.this, 短信已发送, Toast.LENGTH_SHORT ).show(); ); Button bt3 = (Button) findViewById(R.id.Button03); bt3.setOnClickListener(new OnClickListener() Override public void onClick(View v) Intent intent = new Intent( Intent.ACTION_DIAL, Uri.parse(tel:10010); startActivity(intent); ); Button bt4 = (Button) findViewById(R.id.Button04); bt4.setOnClickListener(new OnClickListener() Override public void onClick(View v) Uri uri = Uri.parse(smsto:10010); Intent it = new Intent(Intent.ACTION_SENDTO, uri); it.putExtra(sms_body, 102); startActivity(it); ); 主界面UI定义main.xml 用于监听短信到来的广播消息的文件package jtapp.callandsms;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.telephony.SmsMessage;import android.widget.Toast;public class ReceiverSMS extends BroadcastReceiver Override public void onReceive(Context context, Intent intent) if (intent.getAction().equals( vider.Telephony.SMS_RECEIVED) StringBuilder sb = new StringBuilder(); Bundle bundle = intent.getExtras(); if (bundle != null) Object pdus = (Object) bundle.get(pdus); SmsMessage msgs = new SmsMessagepdus.length; for (int i = 0; i pdus.length; i+) msgsi = SmsMessage .createFromPdu(byte) pdusi); for (SmsMessage s : msgs) sb.append(收到来自); sb.append(s.getDisplayOriginatingAddress(); sb.append(的SMS, 内容:); sb.append(s.getDisplayMessageBody(); Toast.makeText( context, 收到了短消息: + sb.toString(), Toast.LENGTH_LONG).show(); AndroidManifest.xml中权限、activity和receiver的设定: 发email代码块 /Email Button bt5 = (Button) findViewById(R.id.Button05); bt5.setOnClickListener(new OnClickListener() Override public void onClick(View v) / Setup the recipient in a String array String mailto = ; / Create a new Intent to send messages Intent sendIntent = new Intent(Intent.ACTION_SEND); / Write the body of theEmail String emailBody = Youre password is: ; / Add attributes to the intent /sendIntent.setType(text/plain); / use this line for testing / in the emulator sendIntent.setType(message/rfc822); / use this line for testing / on the real phone sendInt

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论