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

android 添加按(power鍵)電源鍵結(jié)束通話(掛斷電話)

 更新時間:2013年01月08日 17:50:05   作者:  
首先我們發(fā)現(xiàn)現(xiàn)在我們所用的android智能手機(jī)大部分都有當(dāng)你在打電話時按power鍵來掛斷電話,一般都是在設(shè)置中
首先我們發(fā)現(xiàn)現(xiàn)在我們所用的android智能手機(jī)大部分都有當(dāng)你在打電話時按power鍵來掛斷電話,一般都是在設(shè)置中。
我主要是在原生源碼中添加這一功能,主要用于學(xué)習(xí)。。。。先看一張圖:
 
看到那個按電源鍵掛斷電話吧,那就是我所添加的,本來原生源碼中是沒有這一欄的。。。。。

大概思路
首先我先添加這一個checkboxPreference,然后將是否選擇這一功能的值(0和1)存到data/data/com.android.providers.settings
/databases/settings.db數(shù)據(jù)庫的system表中
,然后再根據(jù)數(shù)據(jù)庫表中的值在PhoneWindownManager.java中去處理。

具體過程
首先找到setting的源碼,在源碼下我們要找到通話設(shè)置,在seting.xml中我們能找到
復(fù)制代碼 代碼如下:

<SPAN style="FONT-SIZE: 14px"> <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></SPAN>

這個call_settings就是我們在setting(設(shè)置)中看到的通話設(shè)置,但是我們卻不能在settings中的源碼中找到關(guān)于call_settings的布局文件, 因此我們需要找到它,其實(shí)這個布局文件是在package/app/Phone中,也就是在Phone這個app源碼的資源文件中。

因此我們在Phone的資源文件下能找到Call_feature_setting.xml文件如下:
復(fù)制代碼 代碼如下:

<SPAN style="FONT-SIZE: 14px"><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>
。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。
</SPAN>

因此我們可以在最前面添加一個checkboxPreference
復(fù)制代碼 代碼如下:

<SPAN style="FONT-SIZE: 14px"><CheckBoxPreference
android:key="press_power_end_call_key"
android:title="@string/press_power_end_call"
android:persistent="false"/></SPAN>

變成
復(fù)制代碼 代碼如下:

<SPAN style="FONT-SIZE: 14px"><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>
。。。。。。。
。。。。。。。
。。。。。。。</SPAN>

在這里有自己定義的
android:title="@string/press_power_end_call"
所以我們要在資源的string.xml文件中添加相關(guān)的信息:
在package/app/Phone/res/values/string.xml中添加:
<string name="press_power_end_call">press_power_end_call</string>
在package/app/Phone/res/values-zh-rCN/string.xml中添加:
<string name="press_power_end_call" msgid="4676390750360727396">按電源鍵掛斷電話</string>
到這里就算添加好了UI上的東西,接下來就是代碼了:
在package/app/Phone/src/com/android/phone下找到CallFeatureSetting.java文件,
在 public boolean onPreferenceChange(Preference preference, Object objValue) 方法中要增加一個如果選擇了按power鍵掛電話的事件:
復(fù)制代碼 代碼如下:

<SPAN style="FONT-SIZE: 14px">//add by xxnan
else if (preference == press_power_end_call) {
//如果勾選就將1存到system表的press_power_end_call中
Settings.System.putInt(getContentResolver(),
"press_power_end_call",
press_power_end_call.isChecked() ? 1 : 0);
//end by xxnan </SPAN>

在OnCreate添加如下代碼之后
復(fù)制代碼 代碼如下:

protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (DBG) log("Creating activity");
mPhone = PhoneFactory.getDefaultPhone();
addPreferencesFromResource(R.xml.call_feature_setting);
//add by xxnan
ContentResolver resolver = getContentResolver();
press_power_end_call= (CheckBoxPreference)findPreference(press_power_end_call_key);
press_power_end_call.setOnPreferenceChangeListener(this);
// 獲的數(shù)據(jù)庫system表里press_power_end_call的值,也就是是否選擇了checkboxpreference
int press_power_end_call_key=Settings.System.getInt(getContentResolver(),
"press_power_end_call",0);
//如果得到的值是1,則下次打開setting的話,選項框要勾選
if(press_power_end_call_key==1)
press_power_end_call.setChecked(true);
//end by xxnan
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// get buttons
PreferenceScreen prefSet = getPreferenceScreen();
mSubMenuVoicemailSettings = (EditPhoneNumberPreference)findPreference(BUTTON_VOICEMAIL_KEY);
。。。。。。。
。。。。。。。

這樣就算差不多完成了到獲取是否開啟這一功能存放和取出到系統(tǒng)數(shù)據(jù)庫中,接下來就是到framework/base/policy/src/com/android
/internal/policy/impl下的
PhoneWindowManager.java中去處理了,之前我們就有分析到PhoneWindowManager.java中的
public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags, int keyCode, int scanCode, int policyFlags,
boolean isScreenOn)方法來接受按power鍵的事件,在這個方法里我們只需要添加很少代碼:
原來代碼是
復(fù)制代碼 代碼如下:

case KeyEvent.KEYCODE_POWER: {
result &= ~ACTION_PASS_TO_USER;
if (down) {
Log.i("xxnan","xxnan"+"xiaxiangnan");
ITelephony telephonyService = getTelephonyService();
boolean hungUp = false;
if (telephonyService != null) {
try {
if (telephonyService.isRinging()) {
// Pressing Power while there's a ringing incoming
// call should silence the ringer.
telephonyService.silenceRinger();
} else if ((mIncallPowerBehavior
& Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
&& telephonyService.isOffhook()) {
// Otherwise, if "Power button ends call" is enabled,
// the Power button will hang up any current active call.
hungUp = telephonyService.endCall();
}
} catch (RemoteException ex) {
Log.w(TAG, "ITelephony threw RemoteException", ex);
}
}
interceptPowerKeyDown(!isScreenOn || hungUp);
。。。。。。。。。。。。
。。。。。。。。。。。。

修改后
復(fù)制代碼 代碼如下:

case KeyEvent.KEYCODE_POWER: {
result &= ~ACTION_PASS_TO_USER;
if (down) {
Log.i("xxnan","xxnan"+"xiaxiangnan");
int end_call_key=Settings.System.getInt(mContext.getContentResolver(),
"press_power_end_call",0); //取出數(shù)據(jù)庫中是否打開這一功能的值
Log.i("end_call_key","end_call_key="+end_call_key);
ITelephony telephonyService = getTelephonyService();
boolean hungUp = false;
if (telephonyService != null) {
try {
//如果是電話正在打且開啟了這一功能,當(dāng)按power鍵就掛掉電話
if (telephonyService.isRinging()&&end_call_key==1) {
// Pressing Power while there's a ringing incoming
// call should silence the ringer.
// telephonyService.silenceRinger();
hungUp=telephonyService.endCall();
} else if ((mIncallPowerBehavior
& Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
&& telephonyService.isOffhook()) {
// Otherwise, if "Power button ends call" is enabled,
// the Power button will hang up any current active call.
hungUp = telephonyService.endCall();
}
} catch (RemoteException ex) {
Log.w(TAG, "ITelephony threw RemoteException", ex);
}
}
interceptPowerKeyDown(!isScreenOn || hungUp);
。。。。。。。。。。。
。。。。。。。。。。。

由于我這個開發(fā)板上是不能插電話卡的也就沒能實(shí)驗(yàn)成功,但是原理應(yīng)該就這樣的!
最后修改過的地方都要重新編譯,那么我們要在源碼下編譯app下的Phone以及framework下的policy
最后生成的out/。。。/system/app/Phone.apk和out/。。。。/system/framework/android.policy.jar都要替換
手機(jī)里的相同(adb shell 進(jìn)入你的手機(jī),要有root權(quán)限)文件應(yīng)該就可以了。

相關(guān)文章

  • Android?Glide使用方法與原理分析

    Android?Glide使用方法與原理分析

    Android?Glide是一款強(qiáng)大的圖片加載庫,提供了豐富的功能和靈活的使用方式,本文將深入分析Glide的工作原理,并介紹一些使用姿勢,助你更好地運(yùn)用這個優(yōu)秀的庫,需要的朋友可以參考下
    2023-09-09
  • Android多線程學(xué)習(xí)實(shí)例詳解

    Android多線程學(xué)習(xí)實(shí)例詳解

    這篇文章主要介紹了Android多線程,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android多線程的概念、使用方法與相關(guān)注意事項,需要的朋友可以參考下
    2016-10-10
  • Android仿京東搜索框漸變效果

    Android仿京東搜索框漸變效果

    這篇文章主要為大家詳細(xì)介紹了Android仿京東搜索框漸變效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • RecyclerView的簡單使用

    RecyclerView的簡單使用

    這篇文章主要為大家詳細(xì)介紹了RecyclerView的簡單使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Flutter 使用cached_image_network優(yōu)化圖片加載體驗(yàn)

    Flutter 使用cached_image_network優(yōu)化圖片加載體驗(yàn)

    在 Flutter 中,cached_image_network 即提供了緩存網(wǎng)絡(luò)圖片功能,同時還提供了豐富的加載過程指示。本文就來看下cached_image_network的具體使用
    2021-05-05
  • 詳解Android之圖片加載框架Fresco基本使用(二)

    詳解Android之圖片加載框架Fresco基本使用(二)

    本篇文章主要介紹了Android之圖片加載框架Fresco基本使用,可以實(shí)現(xiàn)進(jìn)度條和圖片縮放等內(nèi)容,有興趣的可以了解一下。
    2016-12-12
  • Kotlin協(xié)程Dispatchers原理示例詳解

    Kotlin協(xié)程Dispatchers原理示例詳解

    這篇文章主要為大家介紹了Kotlin協(xié)程Dispatchers原理示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Android WebView輸入框被檔問題升級解析

    Android WebView輸入框被檔問題升級解析

    這篇文章主要為大家介紹了Android WebView輸入框被檔問題升級解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • Kotlin淺析null操作方法

    Kotlin淺析null操作方法

    Kotlin對比于Java的一個最大的區(qū)別就是它致力于消除空引用所帶來的危險。在Java中,如果我們嘗試訪問一個空引用的成員可能就會導(dǎo)致空指針異常NullPointerException(NPE)的出現(xiàn)。在Kotlin語言中就解決了這個問題,下面來看看它是如何做到的
    2022-08-08
  • Kotlin中的惰性操作容器Sequence序列使用原理詳解

    Kotlin中的惰性操作容器Sequence序列使用原理詳解

    這篇文章主要為大家介紹了Kotlin中的惰性操作容器Sequence序列使用原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09

最新評論

收藏| 屏东市| 英山县| 济源市| 广河县| 磴口县| 巨野县| 江口县| 汉源县| 新和县| 眉山市| 措勤县| 鲁甸县| 石渠县| 章丘市| 孝感市| 荔浦县| 拉萨市| 互助| 威信县| 施秉县| 从化市| 洪洞县| 合水县| 昂仁县| 天长市| 尼勒克县| 商都县| 红安县| 化德县| 博白县| 阿克陶县| 永顺县| 台东市| 牡丹江市| 灵台县| 阳新县| 遂宁市| 瑞丽市| 玛沁县| 延安市|