
而要实现手机号码随意打,首先需要像购买ip电话话费一样购买通话时长协同拨号器算号教程,比如300元买500分钟,销售商一般会给你一个像ip电话特服号的号码和某个任意设置电话号码的网站帐号,通过网站帐号便可以设置任何你希望使用的电话号码,每次拨打电话前先拨打这个特服号,接听电话的手机上便可以显示你之前设置好的电话号码,当然更先进一点的也可以通过在手机上安装一个特定的软件来实现上述功能。xml:namespaceprefix=st1/>
Android的手机模拟器自带有拨号功能,我们先试试自带的拨号功能。我们启动两个Android 2.3.3版本的模拟器。你有没有注意每个模拟器左上角有一个这样的
,只不过数字不同,这究竟是什么含义呢?每个模拟器将会被绑定到“192.168.1.1”这个本地IP上,而后面的“5556”则是他的端口号协同拨号器算号教程,所以这个模拟器的唯一标识地是:“192.168.1.1:5556”,所以,这个端口号可以当作是我们的手机号。只要明白了这个,就不会困惑“没有手机号怎么拨打呢?”
打开手机号是“5554”的模拟器,输入“手机号”5556,点击“拨打键”,两个手机则实现通话了:

下面我们自己开发自己的手机拨号器。
●新建Android开发工程
新建项目HTCMobile,选择Android 的版本是2.3.3,项目结构如下所示:

●编写strings.xml文件
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<stringname="hello">HelloWorld,HTCMobileActivity!</string>
<stringname="app_name">HTC拨号器</string>
<stringname="mobile_name">请输入手机号</string>
<stringname="call">拨打此号</string>
</resources>
这个文件主要用来定义字符串和数值
●编写main.xml文件
在项目的res/layout目录下找到此文件
<?xmlversion="1.0"encoding="utf-8"?>

activity_main.xml页面: relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:。main_activity.xml android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/mobile_name"/> <EditText android:id="@+id/phoneNo" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/cllPhone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/call"/> </LinearLayout> 此文件主要设置布局文件,类似于我们的html页面文件,在eclipse中我们可以点击文件编辑区的“Graphical Layout”预览效果: ●编写HTCMobileMobileActivity.java文件 packagecom.sinosoft; importandroid.app.Activity; importandroid.content.Intent; importandroid.net.Uri; importandroid.os.Bundle; importandroid.view.View; importandroid.widget.Button; importandroid.widget.EditText; publicclassHTCMobileActivityextendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); super.onCreate(savedInstanceState); setContentView(R.layout.main); Buttonbutton=(Button)findViewById(R.id.cllPhone); button.setOnClickListener(newView.OnClickListener(){ publicvoidonClick(Viewv){ //TODOAuto-generatedmethodstub EditTextphonenoTest=(EditText)findViewById(R.id.phoneNo);//获得文本框对象 Stringphoneno=phonenoTest.getText().toString();//获得输入的手机号码 if(cachename==null||cachename.trim().equals("")){。if(username == null || "".equals(username.trim())){。if(username==null || "".equals(username.trim())){。 Intentintent=newIntent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneno));//tel:前缀不要写错,用于创建一个拨打电话的意图 startActivity(intent);//发送意图 } } }); } } 具体解释详见注释 ●申请拨号权限 由于我们是拨机系统中的拨号器,因此我们要申请拨打电话的权利,修改AndroidManiFest.xml文件,加入一句: <uses-permissionandroid:name="android.permission.CALL_PHONE" /> 即可,如下所示: <?xmlversion="1.0"encoding="utf-8"?> activity_main.xml页面: relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:。main_activity.xml package="com.sinosoft" android:versionCode="1" android:versionName="1.0"> <uses-sdkandroid:minSdkVersion="10"/> android:minsdkversion="14" android:targetsdkversion="14"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name=".HTCMobileActivity" android:label="@string/app_name"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> 类机器人:名字=“android.intent.category.launcher”/&gt。 android:name=".mainactivity" android:label="@string/app_name"> </intent-filter> </activity> </application> </manifest> 好了,准备工作做完了,开始运行项目,在模拟器里输入另一个模拟器的“手机号码” 点击“拨打此号”按钮时,就会出现用自带拨号器拨打电话的那一幕! 这是本人学习的结果,欢迎转载,欢迎交流,但转载务必给出本文章的链接地址:,谢谢~




本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-106844-1.html
黑芝麻糊