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