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

Android編程簡(jiǎn)單實(shí)現(xiàn)撥號(hào)器功能的方法

 更新時(shí)間:2017年07月26日 09:37:36   作者:青蛙小王子  
這篇文章主要介紹了Android編程簡(jiǎn)單實(shí)現(xiàn)撥號(hào)器功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android撥號(hào)器功能的實(shí)現(xiàn)原理、步驟、操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Android編程簡(jiǎn)單實(shí)現(xiàn)撥號(hào)器功能的方法。分享給大家供大家參考,具體如下:

學(xué)習(xí)Android已經(jīng)有2天時(shí)間了,沒(méi)學(xué)習(xí)的時(shí)候覺(jué)得android可能很枯燥,但是學(xué)過(guò)之后我發(fā)覺(jué)其實(shí)這個(gè)比什么javaweb好玩多了。學(xué)習(xí)android可以見(jiàn)到一些很有趣的東西,這里呢也建議學(xué)習(xí)javaME的人不要在煎熬了,學(xué)習(xí)android吧。在寫程序之前也需要知道android的工作原理

1.獲取組件清單
2.登記或注冊(cè)組件
3.將組件封裝成意圖
4.把意圖交給意圖處理器進(jìn)行處理
5.把界面顯示給用戶

看過(guò)網(wǎng)上android的開(kāi)發(fā)流程,好多人都說(shuō)可以把界面和activity并行開(kāi)發(fā),因?yàn)閍ndroid也是遵循mvc設(shè)計(jì)模式,也就是說(shuō)android也可有自己的業(yè)務(wù)層DAO。由于android發(fā)展歷史比較短,目前的分工還不是很明確,對(duì)于界面和后臺(tái)可以選擇其中一個(gè)作為自己的發(fā)展方向,對(duì)于android的任何一塊來(lái)說(shuō)薪水都比較高。廢話就不多說(shuō)了,來(lái)一步一步的實(shí)現(xiàn)功能吧。

1.編寫“文字”的配置文件,默認(rèn)的配置文件是strings.xml,這里也可以重新寫一個(gè)配置文件,格式要保持一致就來(lái)寫這個(gè)配置文件(mystring.xml)吧

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="tip">輸入號(hào)碼</string>
  <string name="bottonname">撥打</string>
</resources>

2.編寫控件

<?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="@string/tip" />
  <EditText android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/phonenumber"/>  <!-- 顯示一個(gè)文本框 id為phonenumber-->
  <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/bottonname"
    android:id="@+id/botton"
    />  <!-- 顯示一個(gè)按鈕 -->
</LinearLayout>

為了讓大家看的更清楚,我把R文件的內(nèi)容也給大家

/* AUTO-GENERATED FILE. DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found. It
 * should not be modified by hand.
 */
package org.lxh.phone;
public final class R {
  public static final class attr {
  }
  public static final class drawable {
    public static final int icon=0x7f020000;
  }
  public static final class id {
    public static final int botton=0x7f050001;
    public static final int phonenumber=0x7f050000;
  }
  public static final class layout {
    public static final int main=0x7f030000;
  }
  public static final class string {
    public static final int app_name=0x7f040003;
    public static final int bottonname=0x7f040001;
    public static final int hello=0x7f040002;
    public static final int tip=0x7f040000;
  }
}

3.編寫activity

package org.lxh.phone;
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;
public class PhoneActivity extends Activity {
   private EditText edit;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    edit=(EditText)this.findViewById(R.id.phonenumber);  //通過(guò)id取得文本輸入框
    Button but=(Button)this.findViewById(R.id.botton);  //通過(guò)id取得按鈕
    but.setOnClickListener(new MyListener()); //給按鈕添加監(jiān)聽(tīng)器
  }
  public final class MyListener implements View.OnClickListener{  //自定義的監(jiān)聽(tīng)器
    public void onClick(View v) {
      //實(shí)例化一個(gè)意圖(動(dòng)作),用來(lái)?yè)艽螂娫?
      Intent intent=new Intent("android.intent.action.CALL",Uri.parse("tel:"+edit.getText().toString()));
      startActivity(intent); //封裝一個(gè)意圖
    }
  }
}

上面是內(nèi)部類的寫法,也可以使用下面的寫法

package org.lxh.activity;
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;
public class CallPhoneActivity extends Activity {
  private EditText edittext;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //取得輸入框和按鈕
    edittext=(EditText)this.findViewById(R.id.phonenum);
    Button but=(Button)this.findViewById(R.id.button);
    but.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        String number=edittext.getText().toString();
        //封裝一個(gè)意圖,用來(lái)?yè)艽螂娫?
        Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+number));
        startActivity(intent);
      }
    });
  }
}

開(kāi)發(fā)的時(shí)候要注意Uri.parse不能少,tel:也不能少,少了就會(huì)出錯(cuò)

這里要實(shí)現(xiàn)這個(gè)功能,首先要來(lái)看一下xml

<activity android:name="OutgoingCallBroadcaster"
    android:permission="android.permission.CALL_PHONE"
    android:theme="@android:style/Theme.NoDisplay"
    android:configChanges="orientation|keyboardHidden">
  <!-- CALL action intent filters, for the various ways
    of initiating an outgoing call. -->
  <intent-filter>
    <action android:name="android.intent.action.CALL" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="tel" />
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.CALL" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="voicemail" />
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.CALL" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.item/phone" />
    <data android:mimeType="vnd.android.cursor.item/phone_v2" />
    <data android:mimeType="vnd.android.cursor.item/person" />
  </intent-filter>
</activity>

這里只需要看第一個(gè)filter,這里只需使用2條,那個(gè)默認(rèn)的不用我們?nèi)ス?,另外這個(gè)也是需要獲得打電話的許可的,所以在組件清單里要加一點(diǎn)東西,如下所示

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="org.lxh.phone"
   android:versionCode="1"
   android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".PhoneActivity"
         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="7" />
  <uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>

準(zhǔn)備工作差不多做好了,來(lái)測(cè)試一下吧,這里為了測(cè)試方便,我弄了2個(gè)虛擬手機(jī)

電話打通了

這個(gè)比較好玩吧,至于那個(gè)應(yīng)用圖標(biāo)自己可以換成喜歡的,我就不改了

現(xiàn)在把那個(gè)strings.xml配置文件給大家

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="hello">Hello World, PhoneActivity!</string>
  <string name="app_name">我的手機(jī)撥號(hào)器</string>
</resources>

OK了,程序?qū)懞昧恕?/p>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android利用SurfaceView實(shí)現(xiàn)下雨的天氣動(dòng)畫效果

    Android利用SurfaceView實(shí)現(xiàn)下雨的天氣動(dòng)畫效果

    這篇文章主要介紹了Android利用SurfaceView實(shí)現(xiàn)下雨天氣效果的相關(guān)資料,文中詳細(xì)介紹 SurfaceView 和 View 的區(qū)別,以及一些需要使用到 SurfaceView 的場(chǎng)景。需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-03-03
  • Android入門之Style與Theme用法實(shí)例解析

    Android入門之Style與Theme用法實(shí)例解析

    這篇文章主要介紹了Android入門之Style與Theme用法,非常實(shí)用的功能,需要的朋友可以參考下
    2014-08-08
  • 解決video標(biāo)簽在安卓webview下無(wú)法自動(dòng)播放問(wèn)題

    解決video標(biāo)簽在安卓webview下無(wú)法自動(dòng)播放問(wèn)題

    這篇文章主要介紹了video標(biāo)簽在安卓webview下無(wú)法自動(dòng)播放問(wèn)題的解決方法 ,需要的朋友可以參考下
    2014-03-03
  • Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果

    Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • 解決Android Studio 出現(xiàn)“Cannot resolve symbol” 的問(wèn)題

    解決Android Studio 出現(xiàn)“Cannot resolve symbo

    今天在調(diào)試的時(shí)候,Android Studio報(bào)了一個(gè)莫名其妙的錯(cuò)誤Cannot resolve symbol'R'讓人不知所措,因?yàn)檫@東西根本不歸我管啊,怎么會(huì)出現(xiàn) Cannot resolve symbol 這種錯(cuò)誤呢?下面給大家分享Android Studio 出現(xiàn)“Cannot resolve symbol”解決方案,需要的朋友可以參考下
    2023-03-03
  • android SectorMenuView底部導(dǎo)航扇形菜單的實(shí)現(xiàn)代碼

    android SectorMenuView底部導(dǎo)航扇形菜單的實(shí)現(xiàn)代碼

    這篇文章主要介紹了android SectorMenuView底部導(dǎo)航扇形菜單的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • Android自定義Dialog原理實(shí)例解析

    Android自定義Dialog原理實(shí)例解析

    這篇文章主要介紹了Android自定義Dialog原理實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Android中recyclerView底部添加透明漸變效果

    Android中recyclerView底部添加透明漸變效果

    這篇文章主要給大家介紹了關(guān)于Android中recyclerView如何實(shí)現(xiàn)底部添加透明漸變效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2018-04-04
  • Android Studio 1.2版安裝設(shè)置圖文教程

    Android Studio 1.2版安裝設(shè)置圖文教程

    這篇文章主要介紹了Android Studio 1.2版安裝設(shè)置圖文教程,本文詳細(xì)講解了下載、安裝Android Studio 1.2教程,以及常用設(shè)置詳細(xì)圖文教程,需要的朋友可以參考下
    2015-05-05
  • 深入淺析Android坐標(biāo)系統(tǒng)

    深入淺析Android坐標(biāo)系統(tǒng)

    這篇文章主要介紹了 深入淺析Android坐標(biāo)系統(tǒng)的相關(guān)資料,需要的朋友可以參考下
    2016-01-01

最新評(píng)論

临泽县| 穆棱市| 错那县| 罗平县| 洛扎县| 双辽市| 宁陵县| 炉霍县| 渝中区| 鸡西市| 青川县| 句容市| 鱼台县| 陆川县| 玉溪市| 芜湖市| 福安市| 炎陵县| 吉隆县| 松江区| 北辰区| 镶黄旗| 顺平县| 大埔区| 申扎县| 信宜市| 苍山县| 宁阳县| 赫章县| 安平县| 泊头市| 昆明市| 凌海市| 吐鲁番市| 中超| 华坪县| 二连浩特市| 高安市| 唐海县| 醴陵市| 三亚市|