拨打电话需要的权限

<uses-permission android:name="android.permission.CALL_PHONE"/>

为了省事界面都写一起了,有点乱

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <Button
android:id="@+id/btn01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="打开URL" /> <EditText
android:id="@+id/tel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:text="18900008888" /> <Button
android:id="@+id/btn02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="拨打电话" /> <TableLayout
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <TableRow android:id="@+id/TableRow1" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收信人:" /> <EditText
android:id="@+id/msg_tel"
android:layout_width="260px"
android:layout_height="wrap_content"
android:inputType="phone"
android:text="" />
</TableRow> <TableRow android:id="@+id/TableRow2" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="内容:" /> <EditText
android:id="@+id/msg_text"
android:layout_width="260px"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="3" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="发送短信" /> </LinearLayout>
</LinearLayout>

MainActivity.java

public class MainActivity extends Activity {
private Button btn01=null;
private Button btn02=null;
private EditText tel=null;
private EditText msg_tel=null;
private EditText msg_text=null;
private Button btn03=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
this.btn01=(Button)super.findViewById(R.id.btn01);
this.btn01.setOnClickListener(new OnClickListenerImpl()); this.tel=(EditText)super.findViewById(R.id.tel);
this.btn02=(Button)super.findViewById(R.id.btn02);
this.btn02.setOnClickListener(new OnClickListenerImpl()); this.msg_tel=(EditText)super.findViewById(R.id.msg_tel);
this.msg_text=(EditText)super.findViewById(R.id.msg_text);
this.btn03=(Button)super.findViewById(R.id.btn03);
this.btn03.setOnClickListener(new OnClickListenerImpl());
} private class OnClickListenerImpl implements OnClickListener{ @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn01: //打开网页
Uri uri=Uri.parse("http://www.hrb80.com");
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
MainActivity.this.startActivity(intent);
break;
case R.id.btn02: //拨打电话
String telString=MainActivity.this.tel.getText().toString();
Uri uriTel=Uri.parse("tel:"+telString);
Intent intentTel=new Intent();
intentTel.setAction(Intent.ACTION_CALL);
intentTel.setData(uriTel);
MainActivity.this.startActivity(intentTel);
break;
case R.id.btn03: //发送短信
String msg_telString=MainActivity.this.msg_tel.getText().toString();
String msg_textString=MainActivity.this.msg_text.getText().toString();
Uri uriMsg=Uri.parse("smsto:"+msg_telString);
Intent intentMsg=new Intent();
intentMsg.setAction(Intent.ACTION_SENDTO);
intentMsg.putExtra("sms_body", msg_textString);
intentMsg.setType("vnd.android-dir/mms-sms"); //短信的MIME类型
intentMsg.setData(uriMsg);
MainActivity.this.startActivity(intentMsg);
break;
default:
break;
}
}
}

Android 打开URL中的网页和拨打电话、发送短信功能的更多相关文章

  1. Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘

    apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...

  2. android 入门 002 (拨打电话,发送短信)

    一.拨打电话 1.首先做好界面,代码如下: layout =>activity_main.xml 中 <LinearLayout xmlns:android="http://sc ...

  3. 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信

    1.Flutter url_launcher 模块    Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能.    https://p ...

  4. IOS中调用系统拨打电话发送短信

    一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...

  5. Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

    家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...

  6. iOS_拨打电话/发送短信

    GitHub address : https://github.com/mancongiOS/makeACallAndSendMessage.git 功能一: 拨打电话 1.可以有提示框.提示该电话号 ...

  7. android使用Intent操作拨打号码发送短信

    Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...

  8. python-在python3中使用容联云通讯发送短信验证码

    容联云通讯是第三方平台,能够提供短信验证码和语音通信等功能,这里只测试使用短信验证码的功能,因此只需完成注册登录(无需实名认证等)即可使用其短信验证码免费测试服务,不过免费测试服务只能给控制台中指定的 ...

  9. iOS通过openURL打开原生应用与页面(包括电话,短信,safari等)

    [[UIApplication sharedApplication] openURL:url];通过给url不同的值,可以实现调用系统自带 电话/短信/邮箱/浏览器/... 1.调用 电话phone[ ...

随机推荐

  1. c++builder自定义控件

    c++builder自定义控件 http://docwiki.embarcadero.com/CodeExamples/XE8/en/RegisterComponents_%28C%2B%2B%29 ...

  2. directshow 虚拟摄像头 实例 代码解读

    directshow 虚拟摄像头 实例 代码解读 本文只介绍这个源码的大致构成以及怎么修改,因为其他的我也不会啊哈哈哈,我就是用QQ调用虚拟摄像头读取我自己的视频或者图片播放给别人让别人以为这就是实时 ...

  3. vs2012 未找到与约束 ContractName Microsoft.VisualStudio.Utilities.IContentTy...

    错误的大致内容,不能加载某个文件,需要修改web.config文件或者重命名新建.... 周末360大神帮我修复了一下电脑,然而,这一修复导致周一早上的一连串状况, 以上就是错误本尊,刚开始以为同事提 ...

  4. Hello Build To Win!我们是奶牛小分队!——记第一次团队作业

    Hello Build To Win!我们是奶牛小分队! section 1 组建团队 1.  队员介绍: 姓名 学号 风格 擅长技术 编程兴趣 希望软工角色 吴建瑜 2016012024 努力学习, ...

  5. java 蓝桥杯算法提高 _2最大最小公倍数

    解题思路: 1. n是奇数,那就最大的三个数相乘2. n是偶数,得分两种情况了, ①如果n不是3的倍数,那就s=n*(n-1)*(n-3)---n与n-2同为偶数,故排除一个n-2: ②n是3的倍数, ...

  6. SSH(安全协议外壳)介绍及Linux SSH免密登录

    SSH(安全外壳协议) SSH 为 Secure Shell 的缩写,是一种网络安全协议,专为远程登录会话和其他网络服务提供安全性的协议.通过使用 SSH,可以把传输的数据进行加密,有效防止远程管理过 ...

  7. ssh的发展历程与基本原理

    一.ssh是什么 SSH(Secure Shell)是一个提供数据通信安全.远程登录.远程指令执行等功能的安全网络协议,最初提出目的是替代非安全的Telnet.rsh.rexec等远程Shell协议. ...

  8. T-sql GroupBy语句常见问题处理

    1.问题描述 现在有一张course表(含课程编号和名称)和一张sc表(含学生学号,选修课程的编号以及考试成绩),如下:现在想要查询所有课程编号.对应的课程名称以及选修该课程的所有学生的平均成绩.一开 ...

  9. [C++] Memory Retrieval(内存检索)

    Traverse the memory by  (char*) , because every time it will increase by 1byte when i want get the i ...

  10. C++获取字符串长度数

    strlen,获取到的是字节数,中文占两个字节. 如何获取字符数,无论中文英文,标点符号,都按一个字符计算呢?这里提供其中的一个方法.那就是通过MultiByteToWideChar函数,将CStri ...