最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2016年11月10日 11:46:19   作者:楊道龍  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)戰(zhàn)教程第三篇之簡單實(shí)現(xiàn)撥打電話功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android打電話功能的實(shí)現(xiàn)代碼,需要一個(gè)文本輸入框輸入號碼,需要一個(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="請輸入號碼" /> 
 <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)擊偵聽 
  //1.拿到按鈕對象 
  Button bt = (Button) findViewById(R.id.bt_call);//Button類是View的子類,向下轉(zhuǎn)型要強(qiáng)轉(zhuǎn)。 
  //2.設(shè)置偵聽 
  bt.setOnClickListener(new MyListener()); 
 } 
 
 class MyListener implements OnClickListener{ 
 
  //按鈕被點(diǎn)擊時(shí),此方法調(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));//這個(gè)tel:必須要加上,表示我要打電話。否則不會有打電話功能,由于在打電話清單文件里設(shè)置了這個(gè)“協(xié)議” 
    
   //把動作告訴系統(tǒng),啟動系統(tǒng)打電話功能。 
   startActivity(intent); 
  } 
   
 } 
  
} 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

达拉特旗| 荃湾区| 梅州市| 宝兴县| 安义县| 深泽县| 汝城县| 吐鲁番市| 南岸区| 黑河市| 江陵县| 双桥区| 梁平县| 元阳县| 静宁县| 交口县| 板桥市| 新乐市| 泸西县| 丰城市| 文成县| 左权县| 天峻县| 汝南县| 盘山县| 邻水| 西丰县| 嘉禾县| 南涧| 陕西省| 永城市| 于田县| 安乡县| 曲周县| 凤凰县| 临西县| 乾安县| 毕节市| 乌苏市| 法库县| 瓦房店市|