Android 添加按电源键结束通话


首先我们发现现在我们所用的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>
。。。。。。。
。。。。。。。
。。。。。。。

 

  • 1
  • 2
  • 3
  • 下一页

相关内容