Android入门:短信和拨打电话
来源:互联网 发布:python __ 编辑:程序博客网 时间:2024/06/07 14:24
package com.example.sendsms;import java.util.ArrayList;import android.R.array;import android.net.Uri;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.telephony.SmsManager;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final EditText txtNum = (EditText) this.findViewById(R.id.txtNumber);final EditText txtBody = (EditText) this.findViewById(R.id.txtBody);Button btnSms = (Button) this.findViewById(R.id.btnSend);btnSms.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubString num = txtNum.getText().toString();String body = txtBody.getText().toString();SmsManager manager = SmsManager.getDefault();ArrayList<String> list = manager.divideMessage(body);for(String text:list){manager.sendTextMessage(num, null, body, null, null);}}});Button btnCall = (Button) this.findViewById(R.id.btnCall);btnCall.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubString num = txtNum.getText().toString();Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+num));//tel:是必须要这样startActivity(intent);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
(1)SmsManager manager = SmsManager.getDefault(); //获得默认的消息管理器
(2)ArrayList<String> list = manager.divideMessage(String txt); //拆分长短信
(3)manager.sendTextMessage(String phone,null,String content,null,null); //发送短信
加入到权限
1 0
- Android入门:短信和拨打电话
- Android短信和拨打电话
- android中的拨打电话和发送短信
- Android拨打电话和发送短信
- Android 拨打电话和发送短信
- android通讯录:拨打电话和发短信
- Android拨打电话和发送短信操作
- Android拨打电话和发短信
- Android入门(4) 电话拨打与发送短信
- Android开发入门之电话拨打与发送短信
- Android 拨打电话 发短信
- android拨打电话和发送短信核心代码
- Android拨打电话和发短信的简单程序
- 命令行方式向Android模拟器发送短信和拨打电话
- 命令行方式向Android模拟器发送短信和拨打电话
- android中拨打电话和短信发送的实现
- Android中实现拨打电话和发送短信
- 向Android虚拟机发送短信和拨打电话
- 更换服务器后,重新进行域名解析
- iOS OC06_省市区字典数组
- Android 原生 APP
- 关于Spring中MongoTemplate排序问题
- js中onload和$(function(){})的区别
- Android入门:短信和拨打电话
- Scala入门到精通——第六节:类和对象(一)
- linux patch 命令小结
- 用指针数组保存字符串并将字符元素打印输出
- PHP编辑器之Komodo Edit的快捷键
- SpringMVC----初步配置和静态资源无法访问的原因及解决
- 多校1007(最短路+最小割)
- Linux目录结构及文件基本操作
- RHEL一(管理文件、通配符、特殊符号)