拨打电话需要的权限

<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. ffmpeg源码分析一:概述 (转1)

    原帖地址:http://blog.csdn.net/austinblog/article/details/24800381 首先先看ffmpeg.c文件,有类似于如下的一些变量: InputStrea ...

  2. nginx 里设置font-face 跨域

    server { ... # Fix @font-face cross-domain restriction in Firefox location ~* \.(eot|ttf|woff)$ { ad ...

  3. java 蓝桥杯算法提高 出现次数最多的整数

    思路:其实这道题不是太难,但是这个题太坑了,提交了好多次都不是100,后来才知道,一定一定要在输入数组数据之前先判断一下输进去的n的范围,一定一定要注意,否则就是跟我下面的图片一样的效果了,泪奔~ 问 ...

  4. Vertex and fragment programs

    [Vertex and fragment programs] When you use vertex and fragment programs (the so called "progra ...

  5. SpringBoot 集成Mybatis时 使用通用插件Mapper 注意事项

    1.如果在SpringBoot的启动入口类上面加入注解 @MapperScan(basePackages = "com.leecx.mapper")      使用的是   org ...

  6. VS优化编译配置

    在使用VS2010编译C++程序的时候,每次修改工程中的某一个文件,点击“生成-仅用于项目-仅生成**”时,往往都是整个工程都需要重新编译一遍.由于这个工程代码量太大,每次编译完成都需要将近10分钟左 ...

  7. linux的“自动化”-乾颐堂CCIE

    linux系统的web网站在运营状态时,我们常需要对网站进行维护,例如查看资源剩余并做出响应.日志分割.数据整理,在特定状态执行特定任务等等,这些都会需要linux能实现自动执行某些任任务.本篇博文介 ...

  8. [SoapUI] SOAP UI-Groovy Useful Commands

    Hi All, I have posted the SOAPUI and Groovy useful commands that may help you in your testing. Below ...

  9. linux 创建数据库

    mysql -uroot -pxxxxxx 1. 修改服务器的字符集 打开/etc/mysql/my.cnf,在[mysqld]后添加character-set-server=utf8 2. 查看my ...

  10. 解决Emoji存储MySQL报错问题

    在解决之前,得先说明一下为什么会出现报错,Emoji表情占用4个字节,但是MySQL数据库UTF-8编码最多只能存储3个字节,就会导致存储不进去 如何解决Emoji存储问题 mysql 的 utf8编 ...