Android开发六 电话拔号器
效果圖:
因為應(yīng)用要使用手機(jī)的電話服務(wù),所以要在清單文件AndroidManifest.xml中添加電話服務(wù)權(quán)限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
????? package="cn.itcast.action"
????? android:versionCode="1"
????? android:versionName="1.0">
????? 略....
??? <uses-sdk android:minSdkVersion=“8" /><uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>
界面布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
??? android:orientation="vertical"
??? android:layout_width="fill_parent"
??? android:layout_height="fill_parent" >
??? <TextView ?
??? android:layout_width="fill_parent" android:layout_height="wrap_content"
??? android:text="@string/inputmobile"/>
??? <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
??? android:id="@+id/mobile"/>
??? <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
??? android:text="@string/button"
??? android:id="@+id/button"/>
</LinearLayout>
LinearLayout (線性布局)、AbsoluteLayout(絕對布局)、RelativeLayout(相對布局)、TableLayout(表格布局)、FrameLayout(幀布局)
Activity:
public class DialerAction extends Activity {
??? @Override
??? public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);
??????? Button button = (Button)findViewById(R.id.button);
??????? button.setOnClickListener(new View.OnClickListener(){
?? ?public void onClick(View v) {
?? ???????? EditText editText = (EditText)findViewById(R.id.mobile);
?? ???????? Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ editText.getText()));
?? ??????? DialerAction.this.startActivity(intent);
?? ?}
??????? });
??? }
}測試步驟:
?1>在Eclipse中運(yùn)行此應(yīng)用
?2>在Dos窗口中進(jìn)入android SDK安裝路徑的tools目錄,輸入以下命令再開啟一個Android模擬器:
? emulator -data itcast ?
?? 注:itcast為用戶數(shù)據(jù)存取文件,如果該文件不存在,默認(rèn)在tools目錄創(chuàng)建該文件
3>在電話擾號器中輸入上圖現(xiàn)顯的電話號碼
總結(jié)
以上是生活随笔為你收集整理的Android开发六 电话拔号器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 维信维仕担保扣款是什么意思
- 下一篇: 田中理惠(说一说田中理惠的简介)