拨打电话需要的权限

<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. ios学习--详解IPhone动画效果类型及实现方法

    详解IPhone动画效果类型及实现方法是本文要介绍的内容,主要介绍了iphone中动画的实现方法,不多说,我们一起来看内容. 实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一 ...

  2. springboot mvc beetl模板 自定义错误的后缀问题

    @Component public class BeetlErrorViewResolver implements ErrorViewResolver { private static final M ...

  3. cdh 安装步骤

    http://www.cnblogs.com/jasondan/p/4011153.html 关于CDH和Cloudera Manager CDH (Cloudera's Distribution, ...

  4. Cocoapods 版本升级

    和往常一样使用 Cocoapods ,执行命令: $ pod install #输出信息 /System/Library/Frameworks/Ruby.framework/Versions/2.0/ ...

  5. labelimg

    ------------------------labelimg------------------------- cd /home/luo/TensorflowProject/labelImg py ...

  6. 回文链表 · Palindrome Linked List

    [抄题]: 设计一种方式检查一个链表是否为回文链表.1->2->1 就是一个回文链表. [暴力解法]: 时间分析: 空间分析: [思维问题]: 以为要从从后往前扫描,不知道调用revers ...

  7. Spring.net 在aps.net Web的配置复习

    1.引入程序集Spring.Core,CommonLogging,Spring.Web 2.Web.Config的配置 <?xml version="1.0" encodin ...

  8. jstack调试core文件

    摘自:https://stackoverflow.com/questions/37331266/jstack-throws-exception-interrogating-a-core // 错误示例 ...

  9. HUST软工1506班第2周作业成绩公布

    说明 本次公布的成绩对应的作业为: 第2周个人作业:WordCount编码和测试 如果同学对作业成绩存在异议,在成绩公布的72小时内(截止日期4月26日0点)可以进行申诉,方式如下: 毕博平台的第二周 ...

  10. Webstorm 10.0.4 配置

    1. 更换为sublime text的keymaps: https://github.com/ekaragodin/idea-sublime-keymap  (idea-sublime-keymap- ...