Android 實現(xiàn)手機撥打電話的功能
一部手機最常用的功能就是打電話和發(fā)短信了,在Android開發(fā)中我們?nèi)绾瓮ㄟ^程序撥打電話呢?本文就給出一個用Android手機撥打電話的簡單的實例。
下面是開發(fā)此實例的具體步驟:
一、新建一個Android工程,命名為phoneCallDemo。
二、設(shè)計程序的界面,打開main.xml把內(nèi)容修改如下:
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>
三、增加撥打電話的權(quán)限,打開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); //增加事件響應(yīng) bt.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { //取得輸入的電話號碼串 String inputStr = et.getText().toString(); //如果輸入不為空創(chuàng)建打電話的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 開發(fā)撥打電話的簡單示例,后續(xù)繼續(xù)補充相關(guān)資料,謝謝大家對本站的支持!
相關(guān)文章
Kotlin協(xié)程低級api startCoroutine與ContinuationInterceptor
這篇文章主要為大家介紹了Kotlin協(xié)程低級api startCoroutine與ContinuationInterceptor示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-01-01Android應(yīng)用開發(fā)中自定義ViewGroup的究極攻略
這里我們要演示的自定義ViewGroup中將實現(xiàn)多種方式排列和滑動等效果,并且涵蓋子View之間Touch Event的攔截與處理等問題,完全干貨,下面就為大家送上Android應(yīng)用開發(fā)中自定義ViewGroup的究極實例攻略2016-05-05Android實現(xiàn)光點模糊漸變的自旋轉(zhuǎn)圓環(huán)特效
這篇文章主要為大家詳細介紹了Android實現(xiàn)光點模糊漸變的自旋轉(zhuǎn)圓環(huán)特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-06-06Android筆記之:App模塊化及工程擴展的應(yīng)用
這篇文章是android開發(fā)人員的必備知識,是我特別為大家整理和總結(jié)的,不求完美,但是有用2013-04-04Flutter 和 Android 互相傳遞數(shù)據(jù)的實現(xiàn)
這篇文章主要介紹了Flutter 和 Android 互相傳遞數(shù)據(jù)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Android 重力傳感器在游戲開發(fā)中的應(yīng)用
本文主要介紹Android 重力傳感器,這里整理了詳細的資料,并且詳細的說明重力傳感器的使用方法,有興趣的小伙伴可以參考下2016-08-08Android中EditText的drawableRight屬性設(shè)置點擊事件
這篇文章主要介紹了Android中EditText的drawableRight屬性的圖片設(shè)置點擊事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10Android Intent傳遞大量數(shù)據(jù)出現(xiàn)問題解決
這篇文章主要為大家介紹了Android Intent傳遞大量數(shù)據(jù)出現(xiàn)問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07