Android -- make a phone call using Intent--使用意图拨打电话
来源:互联网 发布:android 布局优化 编辑:程序博客网 时间:2024/05/23 00:11
一、File:
package com.jiangge.phonedeom;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;import android.widget.EditText;public class MainActivity extends Activity {EditText editText;Button btnCall;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);editText = (EditText) findViewById(R.id.et_phone);btnCall = (Button) findViewById(R.id.btn_call);btnCall.setOnClickListener(new MyListener());}class MyListener implements OnClickListener{@Overridepublic void onClick(View v) {String number = "tel:" + editText.getText().toString().trim();Intent intent = new Intent();intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse(number));startActivity(intent);}}}
注意:简写
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "电话号码")); startActivity(callIntent);
二、File:布局文件
<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=".MainActivity" > <EditText android:id="@+id/et_phone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:ems="10" android:inputType="phone" /> <Button android:id="@+id/btn_call" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/et_phone" android:layout_marginRight="34dp" android:text="Button" /></RelativeLayout>
注:布局文件可以直接拖拽,id一定要改的规范些,好的编码风格。
三、File: AndroidManifest.xml
拨打电话需要权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
效果图片:
- Android -- make a phone call using Intent--使用意图拨打电话
- Android拨打电话Intent.ACTION.CALL
- Android拨打电话(Intent.ACTION.CALL)
- Action!Call拨打电话(Intent.ACTION.CALL的使用)
- 使用Intent拨打电话
- [Android][M0][Call] 拨打电话
- Android使用Intent实现拨打电话的动作
- Using an Intent to make a photo--Android使用Intent拍照
- android - How to make a phone call from webview
- Inten tAction.CALL的使用,拨打电话
- Android 用Intent直接拨打电话
- Android拨打电话的intent事件
- 使用意图调用内置应用程序—拨打电话
- can I make a cell phone call
- 使用Android拨打电话功能
- 使用Android拨打电话功能
- 使用Android模拟器拨打电话
- Intent拨打电话
- javascript阻止浏览器后退事件。
- [Usaco2011 Jan]道路和航线
- asp.net(C#)中文乱码问题
- 李炎恢jQuery笔记3
- Eclipse "failed to create the java virtual machine"
- Android -- make a phone call using Intent--使用意图拨打电话
- 在html中生成动态地图
- 李炎恢jQuery笔记4过滤选择器
- Spring 3.0 引文注入详解
- UIButton事件
- 李炎恢jQuery笔记5基础DOM和CSS操作
- 2013.11.20
- 李炎恢jQuery笔记6 DOM节点操作
- git 笔记记录(五) git重置