Android 之 自动拨号
[b][size=small][color=olive]介绍:
在自己的小应用中,得到了某些号码,并且希望通过该号码进行拨号,则可以保存当前的
数据,并带到拨号界面,进行拨号;因此诞生了以下代码;[/color][/size][/b]
[size=medium][color=red][b]主要核心代码:[/b][/color][/size]
package com.sun.callphone;
import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.telephony.PhoneNumberUtils;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;
public class MainActivity extends Activity {
//声明对象 private EditText phonenumber ; private Button call,show;
// 程序入口 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
//获取对象 phonenumber = (EditText) findViewById(R.id.phonenumber); call = (Button) findViewById(R.id.call); show = (Button) findViewById(R.id.show);
//点击事件触发 -- 根据用户输入的电话调转到拨号的界面 call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//第一步:获取用户输入数据 String number = phonenumber.getText().toString();
// 第二步:首先判断用户输入的号码是否合乎规范 if(PhoneNumberUtils.isGlobalPhoneNumber(number)){
//第三步:注意权限的使用 //<!-- 获取拨打电话的权限 --> //<uses-permission android:name="android.permission.CALL_PHONE" />
//第四步:开始拨打 Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); // 隐式意图,指定动作 intent.setData(Uri.parse("tel:"+number)); // 带值 startActivity(intent); //开始调转 }else{ Toast.makeText(MainActivity.this, "请重新输入号码!"+number, 2000).show(); } } });
//显示源码 show.setOnClickListener(new OnClickListener() {
public void onClick(View v) { Intent intent = new Intent(); intent.setAction("sun.show"); startActivity(intent);
} }); }}
[size=medium][color=red][b]布局文件:[/b][/color][/size]
<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/phonenumber" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:ems="10" android:hint="input number...." android:inputType="number" />
<Button android:id="@+id/call" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/phonenumber" android:layout_alignParentBottom="true" android:text="拨打测试效果" />
<Button android:id="@+id/show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/call" android:layout_alignLeft="@+id/call" android:layout_alignRight="@+id/call" android:layout_marginBottom="55dp" android:text="查看核心代码及说明" />
</RelativeLayout>
[size=medium][color=red][b]
主配置文件:[/b][/color][/size]
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sun.callphone" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<!-- 获取拨打电话的权限 --> <uses-permission android:name="android.permission.CALL_PHONE" />
<application android:allowBackup="true" android:icon="@drawable/icon_world" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.sun.callphone.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
</manifest>
Android 之 自动拨号相关推荐
- Android 如何自动拨号+拨打电话
定义了一个号码,当有来电时,自动拨打到我定义的号码上. 可是,下面的代码,只能显示出拨号的界面,并自动拨号.但是仍然需要用户手工按一个类似Enter的按钮去拨打. ...
- Android生日礼物(含拼图游戏,背景音乐,自动拨号等功能实现)--根据代码规范修改注释以及定义
公司培训了编码规范,回头过来看看我以前写过的代码,着实比较烂,缺少必要的注释,以及对于变量名的定义也不甚规范,故借着此次学习,我重新整理下一篇安卓项目的文章,规范下代码,可以用doxygen生成htm ...
- android自动拨号 代码,在Android上,是否有一种方法可以强行自动自动拨号?_android_开发99编程知识库...
我一直在研究一个 Android 应用 概念,在用户启动服务时,应用程序必须自动拨号. 我发现,当应用程序尝试自动拨号时,手机( 还是叫 Intent ) 不会自动拨号,而用户必须手动启动服务. 目前 ...
- Android(AIDL)自动重复拨号及挂断/接听电话
Android默认没有提供挂断/接听电话的api,需要伪装com/android/internal/telephony/ITelephony.aidl的接口来欺骗系统.而自动重复拨号可以通过(Broa ...
- android自动拨号112,自动拨号打电话助手
自动拨号打电话助手是一款非常强大拨打电话软件,能够帮助用户更好的拨打电话,给用户节省更多的时间,让用户在打电话的时候能够更加的快速.在平台里,用户可以随时的使用这款软件,能够根据用户设置的时间快速的进 ...
- 自动拨号程序调试过程
想实现一个自动拨号程序,在拨入后能自动输入号码,即能支持10086一类的自动语音系统. 1.最先测试了 Intent intent = new Intent(Intent.ACTION_CAL ...
- linux网卡设置adsl上网,Linux下设置ADSL自动拨号上网
前段时间下载了红帽的linux,版本为redhat 9.0,整整刻了三张CD.最初是为了体验一下linux下QQ聊天软件的功能,最后因内核太低(官方推荐内核在2.6以上,我下载的版本是2.4)而告终. ...
- Android 程序自动更新功能模块实现
2019独角兽企业重金招聘Python工程师标准>>> Android 程序自动更新功能模块实现 在程序启动的时候检测服务器上有没有对应版本更新,如果有更新,提示用户是否更新. 在程 ...
- 使用Java让android手机自动执行重复重启
使用Java让android手机自动执行重复重启 public static void main(String[] args)throws IOException,Exception { for(in ...
- Android应用自动更新功能实现使用AsyncTask!
为什么80%的码农都做不了架构师?>>> 我所开发应用不是面向大众的应用,所以无法放到应用市场去让大家下载,然后通过应用市场更新.所以我必要做一个应用自动更新功能.但是不难,T ...
最新文章
- tomcat文件目录结构及功能介绍
- 基于geopandas的空间数据分析——空间计算篇(下)
- 新浪微博OAuth2.0 VS OAuth1.0 主要区别总结
- php中array_merge()与$arr1+$arr2两个数组直接相加的区别
- UI自动化测试篇 :Selenium2(Webdriver)TestNG自动化测试环境搭建
- 拓端tecdat|Python之LDA主题模型算法应用
- MeasureSpec类
- CentOS7.5部署WeADMIN监控主机交换机配置[详解]
- 广播电台常用51首背景音乐~甘醇永久
- 采样频率和带宽的关系_示波器的采样率及存储深度
- 将越狱进行到底 Pod2g邀约众大神组建evad3rs
- mysql的append用法_insert 中append 用法详解
- 汽车vin码识别简述
- 实现兼容各浏览器的背景渐变,透明度渐变,色彩渐变
- 【English Training】Green Economy and Trade
- 【太虚AR_v0.1】使用教程 | SLAM(Markerless)
- 超好用的PDF阅读器——Xodo PDF Reader
- 去除Opera与迅雷的关联
- 不在上学了能不能考计算机二级,好多学生都问到底要不要参加计算机二级考试?...
- python中dumps是什么意思_python中的dumps和loads区别