android 入门 002 (拨打电话,发送短信)
一、拨打电话
1、首先做好界面,代码如下:
layout =>activity_main.xml 中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/head_lable" /> <EditText
android:id="@+id/txt_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_dialer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨号"
android:layout_gravity="right"
/> </LinearLayout>
效果图如下 :
2、下面就点击拨号事件进行操作:
1)点击拨号按钮=》获取拨号的id==>监听拨号事件setOnClickListener的一个新方法。
2)实现这个方法
2.1)获取编辑框的id==>然后获取其值。
2.2)获取值以后就是要实现打电话的意图啊new一个意图。
意图的动作是打电话、获取电话号码。
2.3)把这个意图告诉系统(startActivity(intent);)
3)加入打电话的权限(在AndroidManifest.xml中)。<uses-permission android:name="android.permission.CALL_PHONE"/>
src=>cn.rfvip.dialer0204=>MainActivity.java 中
package cn.rfvip.dialer0204; import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
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 { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//给按钮一个监听事件
Button bt=(Button) findViewById(R.id.btn_dialer);
bt.setOnClickListener(new MyLisen()); //1、首先获取按钮的id==>然后监听 事件==》获取文本的id==>然后获取其值==》意图是打电话(new一个)==》打电话动作、电话号码(加Tel)。
//把意图告诉系统;
//打电话的权限加入 } class MyLisen implements OnClickListener{ @Override
public void onClick(View v) {
// TODO 自动生成的方法存根 EditText eT=(EditText) findViewById(R.id.txt_number);
String phone=eT.getText().toString(); Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phone));
startActivity(intent);
}} }
二、发送短信
在activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical"
tools:context=".MainActivity" > <EditText
android:id="@+id/ed_sms_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="短信号码"
/>
<EditText
android:id="@+id/ed_sms_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="短信内容"
android:gravity="top"
android:lines="5"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="sengsms"
android:onClick="sendsms"
/> </LinearLayout>
在MainActivity.java
package cn.rfvip.sendsms; import android.os.Bundle;
import android.app.Activity;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.EditText; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendsms(View v) {
EditText ed_sms_phone=(EditText) findViewById(R.id.ed_sms_phone);
EditText ed_sms_content=(EditText) findViewById(R.id.ed_sms_content);
String sms_phone = ed_sms_phone.getText().toString();
String sms_content = ed_sms_content.getText().toString(); SmsManager sm=SmsManager.getDefault();//获取短信管理器
ArrayList<String> smss= sm.divideMessage(sms_content);//分割短信
for(String string:smss)
{
sm.sendTextMessage(sms_phone, null, string, null, null);
}
} }
记得加入发送短信权限哦 <uses-permission android:name="android.permission.SEND_SMS"/>
android 入门 002 (拨打电话,发送短信)的更多相关文章
- Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘
apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...
- iOS_拨打电话/发送短信
GitHub address : https://github.com/mancongiOS/makeACallAndSendMessage.git 功能一: 拨打电话 1.可以有提示框.提示该电话号 ...
- 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信
1.Flutter url_launcher 模块 Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能. https://p ...
- Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序
家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...
- IOS中调用系统拨打电话发送短信
一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...
- android使用Intent操作拨打号码发送短信
Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...
- html5 安卓拨打电话 发短信
方法一: <input name=”phone_no” format=”*m” value=”13″/> <do type=”option” label=”呼出号”> < ...
- android中调用系统的发送短信、发送邮件、打电话功能
1 调用发送短信功能: Uri smsToUri = Uri.parse("smsto:"); Intent sendIntent = new Intent(Intent.ACT ...
- Android面试收集录 电话、短信和联系人、多媒体技术
1.请写出调用系统拨号界面? Intent intent=new Intent(Intent.ACTION_DIAL,Uri.pase("tel:12345678910")); s ...
随机推荐
- JDBC工作模块
jdbc-->java数据库连接 的简称 JDBC工作模块 加载jdbc驱动 与数据库连接 发送sql语句,得到返回结果 处理返回结果 释放资源
- linux第10天 msg消息队列
cat /proc/sys/kernel/msgmax最大消息长度限制 cat /proc/sys/kernel/msgmnb消息队列总的字节数 cat /proc/sys/kernel/msgmni ...
- PTPX中的report 选项
Report的生成 report_power表示产生power report,update_power表示进行power analysis. report_power命令可以生成四种形式的report ...
- IE已经被抛弃,但是不能遗忘
虽然IE的兼容问题,在我写这篇文章的时候基本已经被抛弃了,但是我觉得还是应该了解一下最基本的解决办法. 就像中国的历史已经过去,但是我们不能忘记一样的. 逐个版本解决法 .bb{ background ...
- Sinatra+SQLite3+DataMapper - 十分完整的tutorial - “Superdo”
原文地址:https://ididitmyway.herokuapp.com/past/2010/3/30/superdo_a_sinatra_and_datamapper_to_do_list/ 这 ...
- php导出word格式数据的代码
<?php /** * 生成word文档的类 * by www.jbxue.com */ class word { function start() { ...
- GitHub Desktop for Win 安装不上
采用了ClickOnce部署方式,网速不给力,安装过程经常断线,要是有离线安装包就好了.
- Openstack的HA解决方案【mysql集群配置】
使用mysql的galera做多主集群配置,galera的集群优势网络上面有对比,这里不在叙述. 1. 新建3台虚拟机(centos6.5) node1:172.17.44.163 node2:172 ...
- shell expr 文件扩展名判断 整数判断
expr "text.sh" : ".*\.sh" &>/dev/null && echo "yes" ||e ...
- Bootstrap之Carousel问题
一.不能自动播放的解决办法 1.默认使用Bootstrap的Carousel组件,只需要加上 data-ride="carousel" 就可以实现自动播放了.无需使用初始化的js函 ...