I.MX6 Android 移除 Settings wifi功能

/*********************************************************************
 *              I.MX6 Android 移除 Settings wifi功能
 * 说明:
 *     本文主要记录如何修改Android Settings中的主选项,初衷是有些
 * 设置并不是我们需要,隐藏掉还是比较好的。
 * 
 *                                   2016-3-5 深圳 南山平山村 曾剑锋
 ********************************************************************/

参考文档:
    1. Android Settings开发之修改
        http://blog.csdn.net/wangjinyu501/article/details/22077803
    2. Android Settings和SettingsProvider源码分析与修改
        http://www.cncoders.net/article/11633/
    3. 何时使用 Preference Headers
        http://blog.csdn.net/ixiaobu/article/details/8609935

一、cat packages/apps/Settings/AndroidManifest.xml
    ......
    

    "Settings"                                ------+   
            android:label="@string/settings_label_launcher"                |  
            android:taskAffinity="com.android.settings"                    |  
            android:launchMode="singleTask">                               |  
                                                            |     
            "android.intent.action.MAIN" />           |     
            "android.settings.SETTINGS" />            |      
            "android.intent.category.DEFAULT" />    |      
            "android.intent.category.LAUNCHER" />   |      
                                                           |        
                                                                |  
    ......                                                                 |    
                                                                           |  
二、cat packages/apps/Settings/src/com/android/settings/Settings.java  <---+ 
    ......
     /**
     * Populate the activity with the top-level headers.
     */
    @Override
    public void onBuildHeaders(List
headers) { loadHeadersFromResource(R.xml.settings_headers, headers); | updateHeaderList(headers); | } | ...... | V 三、cat packages/apps/Settings/res/xml/settings_headers.xml ...... ...... 四、error: 1. error 11. 现象: ...... make: Entering directory `/home/myzr/myandroid' target R.java/Manifest.java: Settings (out/target/common/obj/APPS/Settings_intermediates/src/R.stamp) /home/myzr/myandroid/packages/apps/Settings/AndroidManifest.xml:138: error: Error: No resource found that matches the given name (at 'resource' with value '@id/wifi_settings'). /home/myzr/myandroid/packages/apps/Settings/AndroidManifest.xml:151: error: Error: No resource found that matches the given name (at 'resource' with value '@id/wifi_settings'). /home/myzr/myandroid/packages/apps/Settings/AndroidManifest.xml:197: error: Error: No resource found that matches the given name (at 'resource' with value '@id/wifi_settings'). make: *** [out/target/common/obj/APPS/Settings_intermediates/src/R.stamp] Error 1 make: Leaving directory `/home/myzr/myandroid' 2. 解决办法: cat packages/apps/Settings/AndroidManifest.xml ...... ...... 2. error 2: 1. 现象: ...... No private recovery resources for TARGET_DEVICE sabresd_6dq make: Entering directory `/home/myzr/myandroid' target R.java/Manifest.java: Settings (out/target/common/obj/APPS/Settings_intermediates/src/R.stamp) (skipping file '.settings_headers.xml.swp' due to ANDROID_AAPT_IGNORE pattern '.*') target Java: Settings (out/target/common/obj/APPS/Settings_intermediates/classes) /home/myzr/myandroid/packages/apps/Settings/src/com/android/settings/Settings.java:431: cannot find symbol symbol : variable wifi_settings location: class com.android.settings.R.id } else if (id == R.id.wifi_settings) { ^ /home/myzr/myandroid/packages/apps/Settings/src/com/android/settings/Settings.java:602: cannot find symbol symbol : variable wifi_settings location: class com.android.settings.R.id } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) { ^ /home/myzr/myandroid/packages/apps/Settings/src/com/android/settings/Settings.java:700: cannot find symbol symbol : variable wifi_settings location: class com.android.settings.R.id if (header.id == R.id.wifi_settings) { ^ Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 3 errors make: *** [out/target/common/obj/APPS/Settings_intermediates/classes-full-debug.jar] Error 41 make: Leaving directory `/home/myzr/myandroid' 2. 解决办法: cat packages/apps/Settings/src/com/android/settings/Settings.java ...... // Show only these settings for restricted users private int[] SETTINGS_FOR_RESTRICTED = { R.id.wireless_section, //R.id.wifi_settings, R.id.bluetooth_settings, R.id.data_usage_settings, R.id.wireless_settings, R.id.device_section, R.id.sound_settings, R.id.display_settings, R.id.storage_settings, R.id.application_settings, R.id.battery_settings, R.id.personal_section, R.id.location_settings, R.id.security_settings, R.id.language_settings, R.id.user_settings, R.id.account_settings, R.id.account_add, R.id.system_section, R.id.date_time_settings, R.id.about_settings, R.id.accessibility_settings } ...... private void updateHeaderList(List
target) { while (i < target.size()) { Header header = target.get(i); // Ids are integers, so downcasting int id = (int) header.id; if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header); } /** annotation this part else if (id == R.id.wifi_settings) { // Remove WiFi Settings if WiFi service is not available. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { target.remove(i); } } */ else if (id == R.id.bluetooth_settings) { // Remove Bluetooth Settings if Bluetooth service is not available. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { target.remove(i); } } else if (id == R.id.data_usage_settings) { ...... ...... } ...... private static class HeaderAdapter extends ArrayAdapter
{ ...... static int getHeaderType(Header header) { if (header.fragment == null && header.intent == null) { return HEADER_TYPE_CATEGORY; } else if ( /** annotation this part header.id == R.id.wifi_settings || */ header.id == R.id.bluetooth_settings) { return HEADER_TYPE_SWITCH; } else { return HEADER_TYPE_NORMAL; } } ...... } ...... @Override public View getView(int position, View convertView, ViewGroup parent) { ...... // All view fields must be updated every time, because the view may be recycled switch (headerType) { case HEADER_TYPE_CATEGORY: holder.title.setText(header.getTitle(getContext().getResources())); break; case HEADER_TYPE_SWITCH: // Would need a different treatment if the main menu had more switches /** annotation this part if (header.id == R.id.wifi_settings) { mWifiEnabler.setSwitch(holder.switch_); } else { */ mBluetoothEnabler.setSwitch(holder.switch_); /* } */ // No break, fall through on purpose to update common fields //$FALL-THROUGH$ case HEADER_TYPE_NORMAL: if (header.extras != null && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { String accType = header.extras.getString( ManageAccountsSettings.KEY_ACCOUNT_TYPE); ViewGroup.LayoutParams lp = holder.icon.getLayoutParams(); lp.width = getContext().getResources().getDimensionPixelSize( R.dimen.header_icon_width); lp.height = lp.width; holder.icon.setLayoutParams(lp); Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType); holder.icon.setImageDrawable(icon); } else { holder.icon.setImageResource(header.iconRes); } holder.title.setText(header.getTitle(getContext().getResources())); CharSequence summary = header.getSummary(getContext().getResources()); if (!TextUtils.isEmpty(summary)) { holder.summary.setVisibility(View.VISIBLE); holder.summary.setText(summary); } else { holder.summary.setVisibility(View.GONE); } break; } ...... } ......

 

你可能感兴趣的:(I.MX6 Android 移除 Settings wifi功能)