国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 實現手機撥打電話的功能

2019-12-12 05:43:13
字體:
來源:轉載
供稿:網友

一部手機最常用的功能就是打電話和發短信了,在Android開發中我們如何通過程序撥打電話呢?本文就給出一個用Android手機撥打電話的簡單的實例。

       下面是開發此實例的具體步驟:

       一、新建一個Android工程,命名為phoneCallDemo。

       二、設計程序的界面,打開main.xml把內容修改如下:

XML/HTML代碼

<?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="Please input the phoneNumer:"    />    <EditText    android:id="@+id/et1"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:phoneNumber="true"    />    <Button    android:id="@+id/bt1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Call Phone"    />    </LinearLayout> 

  三、增加撥打電話的權限,打開AndroidManifest.xml,修改代碼如下:

XML/HTML代碼

<?xml version="1.0" encoding="utf-8"?>    <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.android.test"    android:versionCode="1"    android:versionName="1.0">    <application android:icon="@drawable/icon" android:label="@string/app_name">    <activity android:name=".PhoneCallDemo"    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-sdk android:minSdkVersion="3" />     <uses-permission android:name="android.permission.CALL_PHONE">    </uses-permission>    </manifest> 

 四、主程序phoneCallDemo.java代碼如下:

 package com.android.test;import android.app.Activity;    import android.content.Intent;    import android.net.Uri;    import android.os.Bundle;    import android.view.View;    import android.widget.Button;    import android.widget.EditText;    import android.widget.Toast;  public class PhoneCallDemo extends Activity {    private Button bt;    private EditText et;    public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    //取得資源    bt = (Button)findViewById(R.id.bt1);    et = (EditText)findViewById(R.id.et1);    //增加事件響應    bt.setOnClickListener(new Button.OnClickListener(){ @Override    public void onClick(View v) {    //取得輸入的電話號碼串    String inputStr = et.getText().toString();    //如果輸入不為空創建打電話的Intent    if(inputStr.trim().length()!=0)    {    Intent phoneIntent = new Intent("android.intent.action.CALL",    Uri.parse("tel:" + inputStr));    //啟動    startActivity(phoneIntent);    }    //否則Toast提示一下    else{    Toast.makeText(PhoneCallDemo.this, "不能輸入為空", Toast.LENGTH_LONG).show();    }    }    });    } 

以上就是Android 開發撥打電話的簡單示例,后續繼續補充相關資料,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐庐县| 宣城市| 子洲县| 镇安县| 定西市| 呼伦贝尔市| 防城港市| 报价| 丹寨县| 莲花县| 苍溪县| 盐亭县| 司法| 浮梁县| 福安市| 梓潼县| 台湾省| 吉木萨尔县| 鹿邑县| 乐东| 灵寿县| 任丘市| 原阳县| 浠水县| 临猗县| 缙云县| 承德县| 澄江县| 涪陵区| 镇安县| 平武县| 桐柏县| 两当县| 错那县| 通海县| 锦屏县| 南木林县| 视频| 北辰区| 边坝县| 东海县|