Android学习笔记_1_拨打电话
2014-02-26 17:05
197 查看
1、首先需要在AndroidManifest.xml文件中加入拨打电话的权限,对应的配置文件:
View Code
2、界面布局
3、Activity类实现,点击事件的实现采用了匿名类的实现方式,
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.test.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> <!-- 权限的作用:包含用户信息安全,当用户在安装软件时会得到安全信息提示,用户判断是否继续进行安装 --> <uses-permission android:name="android.permission.CALL_PHONE"/> </manifest>
View Code
2、界面布局
<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" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hello_world" android:gravity="center" android:textSize="35sp"/> <EditText android:id="@+id/editText1" android:layout_below="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_below="@+id/editText1" android:text="@string/hello_btn" /> </RelativeLayout>
3、Activity类实现,点击事件的实现采用了匿名类的实现方式,
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button)this.findViewById(R.id.btn); final EditText phone = (EditText)this.findViewById(R.id.editText1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String ph = phone.getText().toString(); if(ph!=null && !ph.trim().equals("")){ Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); //intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse("tel:"+ph)); startActivity(intent);//它内部会自动为intent添加类别,上面的内部可以不用写 } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
相关文章推荐
- Android学习笔记_1_拨打电话
- android学习笔记之调用拨号界面拨打电话
- android学习笔记001-拨打电话
- android学习笔记002-拨打电话(优化)
- a标签拨打电话,打开qq,table消除表格间隙
- Android实现拨打电话功能
- iOS给button绑定拨打电话功能
- iOS拨打电话的几种方式
- android拨打电话
- 移动端网页站点调用拨打电话发送短信等功能
- 简单的电话拨打
- 如何修改拨打电话界面输入的数字格式?
- MTK Android拨打电话如何获取适时状态
- wp7手机拨打长途电话
- iOS拨打电话的3种方式(转载)
- android拨打电话
- Android入门(4) 电话拨打与发送短信
- swift 拨打电话
- web页面提供拨打电话与发送邮件的功能
- 用webView加载的方式拨打电话