Google Android 手機程式設計--電話功能(Telephony),衛星定位,藍芽功能

Android 的電話功能主要在android.telephony這個函式庫當中,提供播打與接收電話的功能,其中最重要的兩個物件是 IPhone 和 PhoneNumberUtils.

撥打電話

當你想要在程式中呼叫播打電話的功能時,必需在 AndroidManifest.xml 檔案中將允許程式播打電話的權限打開,其指令如下:

<uses-permission id="android.permission.CALL_PHONE" />

要建立 IPhone 物件,必需透過 ServiceManager 類別,以下是取得 IPhone 的方法:

private static IPhone getPhoneInterface() throws DeadObjectException {

    IServiceManager sm = ServiceManagerNative.getDefault();

    IPhone phoneService = IPhone.Stub.asInterface(sm.getService("phone"));

    return phoneService;

}

一但取得 IPhone 物件後,即可使用 call 或 dial 來撥打電話,然後使用 endCall 來結束通話。 

        void  call(String number) : Place a call to the numer.

        void  dial(String number) : Dial a number.

        void  endCall(boolean hangupOnly) : End call or go to the Home screen 

dial 與 call 之間的差別是 dial 會顯示一個撥號介面,其上填入 number 這個電話號碼 (若 number 是 null,則撥號介面中將不會有預設的號碼)。

另一種撥打電話的方法是對一個電話網址 (例如: tel:0988077312) 送出  CALL_ACTION的動作,即可進行通話供能。

 

另外、你也可以使用 DataStateIntentReceiver 或 PhoneStateIntentReceiver 進行電話事件的註冊,以便取得撥號狀態 (IDLE, RINING, OFF_HOOK)、服務狀態 (in service, out of service, emergency only, powered off, roaming, operator name …)、訊號強度、語音留言、連線狀態 (disconnected、connecting、connected)、資料進出狀態 (data in, data out) 等等。

 

 

取得電話資訊

您也可以透過 TelephonyProperties 中的屬性值,取得許多手機相關的資訊,例如手機的電話號碼、SIM 卡的資訊等等,其方法是使用 os.SystemProperties.get() 函數,傳入 TelephonyProperties 中的對應參數即可取得之,反之、若使用os.SystemProperties.put() 則可設定這些參數。 

範例一:取得 IMEI 國際手機代碼

android.os.SystemProperties.get(PROPERTY_IMEI)

 

範例二:取得手機的電話號碼

android.os.SystemProperties.get(PROPERTY_LINE1_NUMBER)

範例三:取得手機的語音郵件號碼

android.os.SystemProperties.get(PROPERTY_LINE1_VOICE_MAIL_NUMBER)

範例四:取得電信公司的名稱

android.os.SystemProperties.get(PROPERTY_SIM_OPERATOR_ALPHA)

範例五:取得國家的代碼

android.os.SystemProperties.get(PROPERTY_SIM_OPERATOR_ISO_COUNTRY)

衛星定位

與衛星定位相關得兩個函式庫是android.location 與 com.google.android.maps,目前還再草案狀態未定案

 

 

衛星定位的程式

android.location

預計將支援四種地圖相關資訊 (class、kml、nmea、track),其中的 LocationManager 與 LocationProvider 是核心元件。

要取得 Location Manager 的方式必需透過 Context,方法如下:

LocationManager lm = Context.getSystemService(Context.LOCATION_SERVICE);

 

 

控制 Google Map 的顯示

 

com.google.android.maps

此函式庫支援 GoogleMap 應用程式的控制,您可以透過 MapView 物件顯示 GoogleMap ,但前題是您的 Activity 必需繼承 MapActivity

接著您可以透過 MapView 中的 getController() 或 getOverlayController() 去控制 MapView 。

 

在 GoogleMap 上重疊顯示

http://davanum.wordpress.com/2007/11/19/drawing-overlays-for-android-maps-aka-search-for-starbucks/

 

 

藍芽功能

藍芽裝置由於具有獨特的搜尋裝置等特性,因此、某些功能無法納入普通的 TCP/IP 網路功能之下,因此、需要特殊的函式庫支援,在 Android 中,採用的是開放原始碼的 bluez 函式庫 (在 Android 中路徑為 org.bluez)。

開放原始碼的藍芽函式庫 - BlueZ

搜尋藍芽裝置

檔案與物件交換

透過藍芽連上 Internet  自製視覺化元件

http://code.google.com/android/toolbox/custom-components.html

您可以經由繼承 view, layout,或任何從 View 衍生下來的元件以自製.

These steps provide a high level overview of what you need to know to get started in creating your own components:

1.Extend an existing View class or subclass with your own class.

2. Override some of the methods from the superclass: the superclass methods to override start with 'on', for example, onDraw(), onMeasure(), and onKeyDown().

This is similar to the on... events in Activity or ListActivity that you override for life cycle and other functionality hooks.

3. Use your new extension class: once completed, your new extension class can be used in place of the view upon which it was based, but now with the new functionality

 The CustomView sample in the API Demos provides an example of a customized component. The custom component is defined in the LabelView class.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值