阅读更多 介绍:
在自己的小应用中,得到了某些号码,并且希望通过该号码进行拨号,则可以保存当前的
数据,并带到拨号界面,进行拨号;因此诞生了以下代码;


主要核心代码:
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

更多相关文章

  1. android Google Map获取地理位置信息的方法
  2. Android(安卓)frame by frame animation动画显示
  3. android api code 学习之provider包
  4. Android应用获取外部盘符时,默认创建Android/data/包名/files目
  5. Android笔记:Android(安卓)使用Intent拨打电话的两种方式以及差别
  6. android事件处理的四种写法--电话拨号为例
  7. android实现异步加载图片
  8. Android获得Location信息的方法
  9. Android(安卓)APP - GPS定位并获取地理位置

随机推荐

  1. RIL flow
  2. android 上的一个网络接口和图片框架
  3. android hasSystemFeature函数及系统特性
  4. Android(安卓)Internet应用实现获取天气
  5. Android(安卓)NDK开发之Hello world篇
  6. 搭建eclipse android开发环境的一点记录
  7. 【Android】Android(安卓)Support Annota
  8. Android(安卓)跳转到下个Activity并将当
  9. Android(安卓)Camera系统
  10. Android滚动截屏,ScrollView截屏