a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統 > Android > 正文

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

2020-04-11 12:36:00
字體:
來源:轉載
供稿:網友
首先我們發現現在我們所用的android智能手機大部分都有當你在打電話時按power鍵來掛斷電話,一般都是在設置中。
我主要是在原生源碼中添加這一功能,主要用于學習。。。。先看一張圖:
 
看到那個按電源鍵掛斷電話吧,那就是我所添加的,本來原生源碼中是沒有這一欄的。。。。。

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

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

<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(設置)中看到的通話設置,但是我們卻不能在settings中的源碼中找到關于call_settings的布局文件, 因此我們需要找到它,其實這個布局文件是在package/app/Phone中,也就是在Phone這個app源碼的資源文件中。

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

<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
復制代碼 代碼如下:

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

變成
復制代碼 代碼如下:

<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文件中添加相關的信息:
在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鍵掛電話的事件:
復制代碼 代碼如下:

<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添加如下代碼之后
復制代碼 代碼如下:

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);
// 獲的數據庫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);
。。。。。。。
。。。。。。。

這樣就算差不多完成了到獲取是否開啟這一功能存放和取出到系統數據庫中,接下來就是到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鍵的事件,在這個方法里我們只需要添加很少代碼:
原來代碼是
復制代碼 代碼如下:

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);
。。。。。。。。。。。。
。。。。。。。。。。。。

修改后
復制代碼 代碼如下:

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); //取出數據庫中是否打開這一功能的值
Log.i("end_call_key","end_call_key="+end_call_key);
ITelephony telephonyService = getTelephonyService();
boolean hungUp = false;
if (telephonyService != null) {
try {
//如果是電話正在打且開啟了這一功能,當按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);
。。。。。。。。。。。
。。。。。。。。。。。

由于我這個開發板上是不能插電話卡的也就沒能實驗成功,但是原理應該就這樣的!
最后修改過的地方都要重新編譯,那么我們要在源碼下編譯app下的Phone以及framework下的policy
最后生成的out/。。。/system/app/Phone.apk和out/。。。。/system/framework/android.policy.jar都要替換
手機里的相同(adb shell 進入你的手機,要有root權限)文件應該就可以了。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 在线天堂av| 日本一区二区三区视频在线 | 国产一区久久久 | 日韩欧美国产一区二区 | 免费av一区 | 日韩一区二区精品葵司在线 | 日日骚av| 国产色播av在线 | 麻豆精品国产91久久久久久 | 污网站在线观看免费 | 爆操欧美 | 国产精品久久久视频 | 国产伦精品一区二区三区在线 | 欧美性猛交一区二区三区精品 | 极品白嫩少妇无套内谢 | 精品在线免费观看 | 精品国产一区二区三区久久影院 | 欧美激情一区二区 | 久久久亚洲综合 | 国产精品一区二区欧美 | 久久精品视频偷拍 | 成人国产精品久久久 | 成人一级片视频 | 一区二区免费视频观看 | 在线欧美成人 | 福利片在线观看 | 亚洲人人草 | 国产三级日本三级美三级 | 日本免费小视频 | 久久这里有精品 | 日韩久久一区二区 | 久草在线在线精品观看 | 成人欧美一区二区三区在线观看 | 亚洲视频中文字幕 | 国产精品久久婷婷六月丁香 | 国产精品久久久久久久久久久新郎 | 亚色在线 | 国产精品视频不卡 | 国产成人精品高清久久 | 一区二区三区四区国产 | 一本色道久久88综合亚洲精品ⅰ |