Android(安卓)之 自动拨号
16lz
2021-01-26
阅读更多 介绍:
在自己的小应用中,得到了某些号码,并且希望通过该号码进行拨号,则可以保存当前的
数据,并带到拨号界面,进行拨号;因此诞生了以下代码;
主要核心代码:
布局文件:
主配置文件:
在自己的小应用中,得到了某些号码,并且希望通过该号码进行拨号,则可以保存当前的
数据,并带到拨号界面,进行拨号;因此诞生了以下代码;
主要核心代码:
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)){//第三步:注意权限的使用 //////第四步:开始拨打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);}});}}
布局文件:
主配置文件:
<?xml version="1.0" encoding="utf-8"?>
- callphone.rar (1.1 MB)
- 下载次数: 7
更多相关文章
- android Google Map获取地理位置信息的方法
- Android(安卓)frame by frame animation动画显示
- android api code 学习之provider包
- Android应用获取外部盘符时,默认创建Android/data/包名/files目
- Android笔记:Android(安卓)使用Intent拨打电话的两种方式以及差别
- android事件处理的四种写法--电话拨号为例
- android实现异步加载图片
- Android获得Location信息的方法
- Android(安卓)APP - GPS定位并获取地理位置