01电话拨号器
實(shí)例非常簡(jiǎn)單,意在體驗(yàn)Android的Intent,用戶(hù)權(quán)限。
Intent 見(jiàn)?http://blog.csdn.net/zengmingen/article/details/49586045
用戶(hù)權(quán)限 見(jiàn)?http://blog.csdn.net/zengmingen/article/details/49586569
-----------------------------------------------------------------------------------------------
MainActivity.java
package com.example.callPhone;import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.EditText;public class MainActivity extends Activity {private EditText et;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);et=(EditText) findViewById(R.id.phoneNumber);}public void callPhone(View v){String phoneNumber=et.getText().toString();//撥打電話是系統(tǒng)應(yīng)用,谷歌沒(méi)有提供直接的打電話API,需要通過(guò)意圖調(diào)用//創(chuàng)建意圖對(duì)象Intent intent=new Intent();//我們需要告訴系統(tǒng),我們的動(dòng)作:我要打電話intent.setAction(Intent.ACTION_CALL);//把電話號(hào)碼告訴系統(tǒng)的打電話應(yīng)用。這是android系統(tǒng)設(shè)計(jì)思想,組件調(diào)用intent.setData(Uri.parse("tel:" + phoneNumber));startActivity(intent);//現(xiàn)實(shí)中,打電話要錢(qián),所以需要增加打電話權(quán)限}}
AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE"/>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.callPhone"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="17" /><uses-permission android:name="android.permission.CALL_PHONE"/><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name="com.example.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>
activity_main.xml
<LinearLayout 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:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/inputNumber" /><EditTextandroid:id="@+id/phoneNumber"android:layout_width="match_parent"android:layout_height="wrap_content"android:inputType="phone"/><Button android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/callPhone"android:onClick="callPhone"/></LinearLayout>
代碼下載:
http://download.csdn.net/detail/zengmingen/9172881
總結(jié)
- 上一篇: 当使用easyui时,表单的onchan
- 下一篇: zookeeper命令行操作