歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 添加按電源鍵結束通話

Android 添加按電源鍵結束通話

日期:2017/3/1 10:03:39   编辑:Linux編程

首先我們發現現在我們所用的Android智能手機大部分都有當你在打電話時按power鍵來掛斷電話,一般都是在設置中。

我主要是在原生源碼中添加這一功能,主要用於學習。。。。先看一張圖:

看到那個按電源鍵掛斷電話吧,那就是我所添加的,本來原生源碼中是沒有這一欄的。。。。。

大概思路:

首先我先添加這一個checkboxPreference,然後將是否選擇這一功能的值(0和1)存到data/data/com.android.providers.settings

/databases/settings.db數據庫的system表中,然後再根據數據庫表中的值在PhoneWindownManager.java中去處理。

具體過程:

首先找到setting的源碼,在源碼下我們要找到通話設置,在seting.xml中我們能找到

<com.android.settings.IconPreferenceScreen
android:key="call_settings"
settings:icon="@drawable/ic_settings_call"
android:title="@string/call_settings_title">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.phone"
android:targetClass="com.android.phone.CallFeaturesSetting" />
</com.android.settings.IconPreferenceScreen>

這個call_settings就是我們在setting(設置)中看到的通話設置,但是我們卻不能在settings中的源碼中找到關於call_settings的布局文件,

因此我們需要找到它,其實這個布局文件是在package/app/Phone中,也就是在Phone這個app源碼的資源文件中。

因此我們在Phone的資源文件下能找到Call_feature_setting.xml文件如下:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:phone="http://schemas.android.com/apk/res/com.android.phone"
android:title="@string/call_settings">
<PreferenceScreen
android:key="button_fdn_key"
android:title="@string/fdn"
android:summary="@string/sum_fdn"
android:persistent="false">

<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.phone"
android:targetClass="com.android.phone.FdnSetting" />

</PreferenceScreen>

<PreferenceCategory
android:key="button_voicemail_category_key"
android:title="@string/voicemail"
android:persistent="false">
<ListPreference
android:key="button_voicemail_provider_key"
android:title="@string/voicemail_provider"
android:summary="@string/sum_voicemail_choose_provider"
android:defaultValue=""
android:persistent="true"
/>
<PreferenceScreen android:key="button_voicemail_setting_key"
android:title="@string/voicemail_settings"
android:persistent="false">

<!-- Note for all com.android.phone.EditPhoneNumberPreference objects

The last several attributes are for use with the EditText field
in the dialog. These attributes are forwarded to that field
when the edittext is created. The attributes include:
1. android:singleLine
2. android:autoText
3. android:background -->

<com.android.phone.EditPhoneNumberPreference
android:key="button_voicemail_key"
android:title="@string/voicemail_settings_number_label"
android:persistent="false"
android:dialogTitle="@string/voicemail"
phone:confirmMode="confirm"
android:singleLine="true"
android:autoText="false" />
</PreferenceScreen>
</PreferenceCategory>
。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。

因此我們可以在最前面添加一個checkboxPreference

<CheckBoxPreference
android:key="press_power_end_call_key"
android:title="@string/press_power_end_call"
android:persistent="false"/>

變成:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:phone="http://schemas.android.com/apk/res/com.android.phone"
android:title="@string/call_settings">
<CheckBoxPreference
android:key="press_power_end_call_key"
android:title="@string/press_power_end_call"
android:persistent="false"/>

<PreferenceScreen
android:key="button_fdn_key"
android:title="@string/fdn"
android:summary="@string/sum_fdn"
android:persistent="false">

<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.phone"
android:targetClass="com.android.phone.FdnSetting" />

</PreferenceScreen>
。。。。。。。
。。。。。。。
。。。。。。。

Copyright © Linux教程網 All Rights Reserved