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

首頁(yè) > 系統(tǒng) > Android > 正文

Android實(shí)戰(zhàn)教程第三篇之簡(jiǎn)單實(shí)現(xiàn)撥打電話功能

2019-12-12 04:43:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例為大家分享了Android打電話功能的實(shí)現(xiàn)代碼,需要一個(gè)文本輸入框輸入號(hào)碼,需要一個(gè)按鈕打電話。

本質(zhì):點(diǎn)擊按鈕,調(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="請(qǐng)輸入號(hào)碼" />  <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è)置點(diǎn)擊偵聽(tīng)   //1.拿到按鈕對(duì)象   Button bt = (Button) findViewById(R.id.bt_call);//Button類是View的子類,向下轉(zhuǎn)型要強(qiáng)轉(zhuǎn)。   //2.設(shè)置偵聽(tīng)   bt.setOnClickListener(new MyListener());  }   class MyListener implements OnClickListener{    //按鈕被點(diǎn)擊時(shí),此方法調(diào)用   @Override   public void onClick(View v) {    //獲取用戶輸入的號(hào)碼    EditText et = (EditText) findViewById(R.id.et_phone);    String phone = et.getText().toString();        //我們需要告訴系統(tǒng),我們的動(dòng)作:我要打電話    //創(chuàng)建意圖對(duì)象    Intent intent = new Intent();    //把打電話的動(dòng)作ACTION_CALL封裝至意圖對(duì)象當(dāng)中    intent.setAction(Intent.ACTION_CALL);    //設(shè)置打給誰(shuí)    intent.setData(Uri.parse("tel:" + phone));//這個(gè)tel:必須要加上,表示我要打電話。否則不會(huì)有打電話功能,由于在打電話清單文件里設(shè)置了這個(gè)“協(xié)議”        //把動(dòng)作告訴系統(tǒng),啟動(dòng)系統(tǒng)打電話功能。    startActivity(intent);   }     }   } 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 封丘县| 东莞市| 枝江市| 汽车| 道真| 丰顺县| 祁门县| 盱眙县| 太仆寺旗| 北票市| 无极县| 东明县| 绥阳县| 托里县| 乐清市| 曲水县| 寻甸| 都匀市| 清新县| 双江| 合江县| 泌阳县| 曲沃县| 泾川县| 谷城县| 永登县| 威海市| 峨边| 闵行区| 曲水县| 长宁县| 辉县市| 登封市| 安图县| 磐安县| 南康市| 泸西县| 勃利县| 金阳县| 宽甸| 穆棱市|