安卓小程序——实现两个模拟器之间的电话拨号
养成良好的代码习惯,使代码尽量国际化。这是跟着传智播客黎活明老师学习3G手机android教程,写下的学习博客。


main.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/mobile"
android:hint="@string/mobile" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button"
android:id="@+id/button" />
</LinearLayout>

String.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Itcast_01_callphone</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="mobile">请输入手机号</string>
<string name="button">拨打此号码</string>

</resources>


MainActivity.java 文件
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
EditText mobileText = (EditText) findViewById(R.id.mobile);
String mobile = mobileText.getText().toString();
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.setData(Uri.parse("tel:"+ mobile));
startActivity(intent);
}
});
}

}



代码写完了以后,我们得在AndroidManifest中加入权限:
<uses-permission android:name="android.permission.CALL_PHONE" />

这个权限是拨打电话的权限,我们必须启动2个模拟器才能互相打电话。

下载代码:http://download.csdn.net/detail/u012301841/7583595

更多相关文章

  1. Android手机归属地查询工具
  2. Android之greenDao,一个orm的使用
  3. Android(安卓)反编译代码和资源
  4. eclipse下使用MultiDex解决65536限制
  5. Android本地图片上传(拍照+相册)
  6. android 打包 生成apk 出现的问题 javascript失效 json解析失败
  7. android选择视频文件上传到后台服务器
  8. android如何使用自定义JNI接口,以及NDK工具的环境搭建与使用。
  9. Android音频流程二(Binder部分)

随机推荐

  1. DDNS 的工作原理及其在 Linux 上的实现--
  2. Linux:/etc/hosts中的127.0.0.1作用
  3. 双机高可用、负载均衡、MySQL(读写分离、
  4. 我想开始学习Linux网络编程和android开发
  5. 《鸟哥的Linux私房菜》读书笔记6——其它
  6. Linux 下nice 函数用法提高一个进程的友
  7. Ubuntu系统环境变量详解
  8. Linux下安装和使用杀毒软件AntiVir
  9. Linux-C语言函数手册
  10. Linux的那些事儿(10)----grep命令以及正则