拨打电话需要的权限

<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. Maven中dependencyManagement使用

    在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器. 在dependencyManagement下申明的dependencies,Maven ...

  2. Android MVP模式简单易懂的介绍方式 (一)

    Android MVP模式简单易懂的介绍方式 (一) Android MVP模式简单易懂的介绍方式 (二) Android MVP模式简单易懂的介绍方式 (三) 最近正在研究Android的MVP模式 ...

  3. Java Tutorial

    http://www.tutorialspoint.com/java/index.htm

  4. shell编程——内部变量

    常用的内部变量有:echo, eval, exec, export, readonly, read, shift, wait, exit 和 点(.) echo:将变量名指定的变量显示到标准输出 [r ...

  5. 浅谈JobExecutionContext&JobDataMap

  6. onload函数和自执行函数的区别(jquery API网址:http://jquery.cuishifeng.cn/)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. kubenetes dns

    E0228 07:32:28.912833       1 reflector.go:201] k8s.io/dns/pkg/dns/dns.go:147: Failed to list *v1.En ...

  8. C# Equals

    [C# Equals] 1.Object.Equals() The type of comparison between the current instance and the obj parame ...

  9. Unity strip engine code 遇到執行不能之問題與解決

    遊戲發布在 WebGL 平台發現檔案還是太大,因此在 IL2CPP 的環境下,開啟 Strip engine code 編譯功能,嘗試看看能不能減少一些檔案容量. 但由於我們另外有載入 Scene s ...

  10. 混合开发之DSBridge(同时支持Android和iOS)

    什么是 Javascript bridge 随着h5的不断普及及优化,以及移动端对动态化的需求越来越大,开发者经常需要在app中嵌入一些网页,然后会在web和native之间进行交互,如传递数据,调用 ...