介绍:
在自己的小应用中,得到了某些号码,并且希望通过该号码进行拨号,则可以保存当前的
数据,并带到拨号界面,进行拨号;因此诞生了以下代码;
主要核心代码:
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);
}
});
}
}
布局文件:
<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>
主配置文件:
<?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的自动拨号程序 http://hi.baidu.com/widebright/item/5139010afb6703dd73e676a8代码整合
我自己写的,自动拨号软件,写着玩。
android上自动拨号,春节购票必备.源码。。。 开发
android 自动重拨软件源码,用户可以手动输入号码,输入重复次数,中途可以切换进来手动停止
摸索了很长时间,终于实现了自动拨号; 网上查看了很多相关的例子,发现只能调用到系统拨号的界面,后面还是需要自己去点拨打,没有满足自己的需求,所以找了很长时间的资料,实现了真正的拨号功能,希望能帮到下载的人
该文件时apk文件,已经成功的帮我同事和其他朋友预定到回家的票,需要回家电话订票的朋友可不能错过
公司的一个同事开发的一个小程序,专门针对火车票电话订票困难的情况,可以自动拨号。解放你的双手吧,请带上耳机静静等待...
android实现拨号功能,在页面内输入电话号码,有空格会自动处理,然后点击拨号,连同号码一起跳转到拨号界面,如果要直接拨号,秩序改动一个参数即可
过年了订火车票电话难打进去,用这个软件自动重拨,能提高一些效率,祝大家能早点订到车票
Android例子源码实现定时拨号功能是一个通过android平台实现时时拨号与定时拨号的功能的例子源码,使用多线程实现。注释比较全,适合新手学习参考
Android 实现电脑自动拨号软件,支持honor 20 ,小米8 使用技术:Android ,springboot,netty,mysql,
安装点击运行之后,可实现自动拨号,并显示自定义的界面
输入电话号码和间隔时间(以分钟为单位),就可以反复拨打号码
春运来到,我们需要订火车票,特制作一个疯狂拨号软件,一直拨到对方电话号码通为止!
EC20 4G模块拨号上网驱动包括Linux、window、Android、WINCE等。 每个子文件夹里面有对应的上网教程!可以点主页查看上网教程。
Android替换系统来电页面,支持自定义图片,视频,屏幕锁定时可自动唤醒
拨号 Android 应用程序。 Diial 是一款移动应用程序,它利用智能手机的功能来改善客户服务呼叫。 此存储库包含用于 Diial 的完整 Android 应用程序。 [Google Play 链接] ( ) 组件 ###教学调用树 搜索任何公司 快速...
ec20模块qmi_wwan拨号工具
实现自动拨打特定号码,打不通就一直打,直到所有号码都没打通为止。