Android 打开URL中的网页和拨打电话、发送短信功能
拨打电话需要的权限
<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中的网页和拨打电话、发送短信功能的更多相关文章
- Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘
apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...
- android 入门 002 (拨打电话,发送短信)
一.拨打电话 1.首先做好界面,代码如下: layout =>activity_main.xml 中 <LinearLayout xmlns:android="http://sc ...
- 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信
1.Flutter url_launcher 模块 Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能. https://p ...
- IOS中调用系统拨打电话发送短信
一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...
- Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序
家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...
- iOS_拨打电话/发送短信
GitHub address : https://github.com/mancongiOS/makeACallAndSendMessage.git 功能一: 拨打电话 1.可以有提示框.提示该电话号 ...
- android使用Intent操作拨打号码发送短信
Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...
- python-在python3中使用容联云通讯发送短信验证码
容联云通讯是第三方平台,能够提供短信验证码和语音通信等功能,这里只测试使用短信验证码的功能,因此只需完成注册登录(无需实名认证等)即可使用其短信验证码免费测试服务,不过免费测试服务只能给控制台中指定的 ...
- iOS通过openURL打开原生应用与页面(包括电话,短信,safari等)
[[UIApplication sharedApplication] openURL:url];通过给url不同的值,可以实现调用系统自带 电话/短信/邮箱/浏览器/... 1.调用 电话phone[ ...
随机推荐
- 关于junit包导入不了但是maven本地库中却存在的问题
导入项目的时候发现junit的类使用不了,于是就去看看包导入了没有 发现包是灰色的,于是猜想可能是maven本地库中包没下载过来 查询了本地库发现包是存在的,这就奇怪的,经过网上查询之后得到解决方案 ...
- 清除html中的标记,只留下文字
/// <summary>/// 清除html中的标记,只留下文字./// </summary>/// <param name="HTML">& ...
- centos7的vsftpd的安装和配置
安装vsftpd的服务器相关软件 安装vsftpd服务器和客户端 sudo yum install ftp vsftpd 安装一个加密工具 sudo yum install libdb-utils.x ...
- 为什么3D模型的网格由很多三角形来组成
因为二点确定一条线,三点确定一个面 网格就是由很多面组成的,四个点也能组成面 但是三个点就足够了
- php实现二分查找法
二分查找法需要数组是一个有序的数组 假设我们的数组是一个递增的数组,首先我们需要找到数组的中间位置. 一.要知道中间位置就需要知道起始位置和结束位置,然后取出中间位置的值来和我们的值做对比. 二.如果 ...
- TCP、UDP、HTTP、SOCKET之间的区别与联系-乾颐堂CCIE
IP:网络层协议: TCP和UDP:传输层协议: HTTP:应用层协议: SOCKET:TCP/IP网络的API. TCP/IP代表传输控制协议/网际协议,指的是一系列协议. TCP和UDP使用IP协 ...
- Smarty的条件判断语句
(1)基本句式{if $name eq "Fred"}Welcome Sir.{elseif $name eq "Wilma"}Welcome Ma'am.{e ...
- IO编程之writelines方法
1.使用with open as 函数写入文件 2.创建后的文件名为database.txt 3.创建一个函数进行读取文件,使用for循环遍历整个文件内容 4.使用if __name__=='__ma ...
- Qt编译,imp_CommandLineToArgvW@8问题
Tested msvc2013. The linker can not find _imp_CommandLineToArgvW@8. It's in shell32.lib. I see qtmai ...
- kubernetes使用ceph
一.有一个ceph cluster,假设已经准备好了,文档网上一大堆 二.开始集成ceph和kuberntes 2.1 禁用rbd features rbd image有4个 features,lay ...