Android實戰(zhàn)教程第三篇之簡單實現(xiàn)撥打電話功能
更新時間:2016年11月10日 11:46:19 作者:楊道龍
這篇文章主要為大家詳細(xì)介紹了Android實戰(zhàn)教程第三篇之簡單實現(xiàn)撥打電話功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Android打電話功能的實現(xiàn)代碼,需要一個文本輸入框輸入號碼,需要一個按鈕打電話。
本質(zhì):點擊按鈕,調(diào)用系統(tǒng)打電話功能。
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" tools:context=".MainActivity" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="請輸入號碼" /> <EditText android:id="@+id/et_phone" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/bt_call" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="撥打" /> </LinearLayout>
mainactivity中代碼:
package com.ydl.dialer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//給按鈕設(shè)置點擊偵聽
//1.拿到按鈕對象
Button bt = (Button) findViewById(R.id.bt_call);//Button類是View的子類,向下轉(zhuǎn)型要強轉(zhuǎn)。
//2.設(shè)置偵聽
bt.setOnClickListener(new MyListener());
}
class MyListener implements OnClickListener{
//按鈕被點擊時,此方法調(diào)用
@Override
public void onClick(View v) {
//獲取用戶輸入的號碼
EditText et = (EditText) findViewById(R.id.et_phone);
String phone = et.getText().toString();
//我們需要告訴系統(tǒng),我們的動作:我要打電話
//創(chuàng)建意圖對象
Intent intent = new Intent();
//把打電話的動作ACTION_CALL封裝至意圖對象當(dāng)中
intent.setAction(Intent.ACTION_CALL);
//設(shè)置打給誰
intent.setData(Uri.parse("tel:" + phone));//這個tel:必須要加上,表示我要打電話。否則不會有打電話功能,由于在打電話清單文件里設(shè)置了這個“協(xié)議”
//把動作告訴系統(tǒng),啟動系統(tǒng)打電話功能。
startActivity(intent);
}
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android無需申請權(quán)限撥打電話的兩種方式
- Android撥打電話功能實例詳解
- 編寫android撥打電話apk應(yīng)用實例代碼
- Android 實現(xiàn)手機撥打電話的功能
- Android中Webview打開網(wǎng)頁的同時發(fā)送HTTP頭信息方法
- Android實現(xiàn)將應(yīng)用崩潰信息發(fā)送給開發(fā)者并重啟應(yīng)用的方法
- Android發(fā)送短信功能代碼
- Android Mms之:短信發(fā)送流程(圖文詳解)
- Android實現(xiàn)發(fā)送短信功能實例詳解
- android中可以通過兩種方式調(diào)用接口發(fā)送短信
- Android開發(fā)實現(xiàn)撥打電話與發(fā)送信息的方法分析
相關(guān)文章
Flutter開發(fā)之對角棋游戲?qū)崿F(xiàn)實例詳解
這篇文章主要為大家介紹了Flutter開發(fā)之對角棋游戲?qū)崿F(xiàn)實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
Android數(shù)據(jù)持久化之讀寫SD卡中內(nèi)容的方法詳解
這篇文章主要介紹了Android數(shù)據(jù)持久化之讀寫SD卡中內(nèi)容的方法,結(jié)合具體實例形式分析了Android持久化操作中針對SD卡進行讀寫操作的相關(guān)實現(xiàn)技巧與注意事項,需要的朋友可以參考下2017-05-05
基于Android studio3.6的JNI教程之ncnn之語義分割ENet
這篇文章主要介紹了基于Android studio3.6的JNI教程之ncnn之語義分割ENet的相關(guān)知識,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值 ,需要的朋友可以參考下2020-03-03
android 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法
下面小編就為大家?guī)硪黄猘ndroid 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03

