android 使用意图(Intent)实现一键拨号实例
来源:互联网 发布:子域名怎么看 编辑:程序博客网 时间:2024/05/16 04:37
本文打算实现具有一个一键拨号功能的 APP
1.布局文件activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.sehzh.intenttester.MainActivity" > <Button android:id="@+id/mCallButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="26dp" android:text="Call" /></RelativeLayout>2.MainActivity
package cn.sehzh.intenttester;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {private Button mBtn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mBtn = (Button) findViewById(R.id.mCallButton);mBtn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {dialPhoneNumber("110");}});}private void dialPhoneNumber(String phoneNumber) {Intent intent = new Intent(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:" + phoneNumber));if (intent.resolveActivity(getPackageManager()) != null) {startActivity(intent);}}}3.运行效果
4.注意
Intent intent = new Intent(Intent.ACTION_CALL);中的ACTION_CALL如果写为ACTION_DIAL则会跳出带键盘拨号界面,而不是直接拨打电话;
需要以下权限
<uses-permission android:name="android.permission.CALL_PHONE" />
1 0
- android 使用意图(Intent)实现一键拨号实例
- Intent使用意图(一)添加Category
- Android-Intent(意图)
- Intent使用意图(三)
- Intent使用意图(二)
- Andriod使用Intent实现拨号
- Intent使用意图(二)添加Android 内置的ACTION
- Intent 意图简单使用实现页面跳转
- Android中的Intent(意图)的使用
- Android中的Intent(意图)的使用
- Android 意图和意图过滤器(一)
- 8、Android中Intent(意图)
- android中的Intent(意图)理解
- Android自学笔记-14-意图(Intent)
- android--Intent 意图 (待写待整理)
- android(28)(intent隐式意图)
- Android学习笔记之Intent(意图)
- 关于android开发中的Intent(意图)
- 09 redis集群的搭建 以及遇到的问题
- UVA - 729 The Hamming Distance Problem
- 给RecyclerView最纯粹的下拉刷新和上拉加载更多
- [poj1511] Invitation Cards
- JSP 使用<%@include%>报Duplicate local variable path 错误 解决方法
- android 使用意图(Intent)实现一键拨号实例
- 软件设计师——计算机与软件工程知识&学习要点(上午题A)
- 二十岁出头,你一无所有,但你却拥有一切(转载)
- HDU 5652 India and China Origins (并查集判断联通)
- 最新版oracle安装
- Java第十二天
- dapper orm
- 史上最稳定万能视频解析接口
- CF 616F Expensive Strings 用到fail链性质的SAM练手题