Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,742,742 Members 37,640 Now Online
XDA Developers Android and Mobile Development Forum
View Poll Results: Was it Helpful?
Yes! 15 93.75%
No. 1 6.25%
Voters: 16. You may not vote on this poll

[Tutorial] Adding new Activity Header/Sub Menu to Settings.apk

Tip us?
 
Madaditya
Old
(Last edited by Madaditya; 10th April 2014 at 12:11 PM.)
#1  
Madaditya's Avatar
Recognized Themer - OP
Thanks Meter 962
Posts: 936
Join Date: Jul 2012
Location: No where
Post [Tutorial] Adding new Activity Header/Sub Menu to Settings.apk

Hi Geeks

Here's a tutorial on how to add an Activity Header to Settings.apk

Requirements:

1.Settings.apk
2.Notepad ++ or Editor Alternatives
3.Apktool to Decompile apk
4.A Little Common sense

Tutorial:

1. Decompile Settings.apk

2.Open to res/xml/settings_headers.xml

3.Lets take an example i want to Add "Maddy" as a activity header



add this line

Code:
Select Code
 <header android:icon="@drawable/ic_settings_maddy" android:id="@id/maddy_settings" android:title="@string/maddy_settings" android:fragment="com.android.settings.Maddy" />
The layout in settings_headers.xml is categorized. If you want submenu "Maddy" to appear after 'Apps' as shown,add the line after the line that says <header android:icon="@drawable/ic_settings_applications"..... as shown

Code:
Select Code
 <header android:icon="@drawable/ic_settings_applications" android:id="@id/application_settings" android:title="@string/applications_settings" android:fragment="com.android.settings.applications.ManageApplications" />
 <header android:icon="@drawable/ic_settings_maddy" android:id="@id/maddy_settings" android:title="@string/maddy_settings" android:fragment="com.android.settings.Maddy" />

3.1-@drawable/ic_settings_maddy=This refers to the png in res/drawable-*dpi/ folder

Add a new png named ic_settings_maddy.png in res/drawable-*dpi/
It will be the Image that will show up in settings menu (The Wifi like icon in my case)

* = hdpi / mdpi /xhdpi /xxhdpi /xxxhdpi (Depends on your device)




3.2-@id/maddy_settings=This refers to id value in /res/values/ids.xml

Open res/values/ids.xml and add this code

Code:
Select Code
<item type="id" name="maddy_settings">false</item>


3.3 - @string/maddy_settings = Refers to a string in res/values/strings.xml

Open strings.xml and add this code

Code:
Select Code
<string name="maddy_settings">Your String here</string>
Add the string you wish to see in settings Submenu in place of 'Your String Here'



3.4-com.android.settings.Maddy = Refers to the smali file in smali/com/android/settings/


4. Open res/values/public.xml
and find the last line that says
<public type="xml" ...

like
Code:
Select Code
<public type="xml" name="somethig_something" id="0x7f050053" />
Note the Hex code in Blue.It can be different for you
and now add this line just after the last line of type="xml"

Code:
Select Code
<public type="xml" name="maddy_settings" id="0x7f050054" />
Also Note that the previous address in my case was 0x7f050053
so the new address will be "Previous address + 1(Hex addition)" i.e 0x7f050054

Replace 0x7f050054 with your calculated Address.



If your Address is 0x7f050039
Next Addres = 0x7f05003a

if your address is 0x7f05003f
next address = 0x7f050040
and so on..

5.Go to res/xml/
and add a new file named maddy_settings.xml

This xml would contain the Apps/Actions you wish to see inside the Submenu "Maddy"

Just like you see

Brightness
Screen timeout
etc etc

options when you click Display in Settings Menu
an example of what maddy_settings.xml may contain

 
PHP Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:title="@string/maddy_settings"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
    <com.sonymobile.settings.preference.PreferenceCategory android:title="@string/uipref_title">
        <PreferenceScreen android:icon="@drawable/cust_bar_wallpapers" android:title="@string/wallpaper_settings_title" android:key="wallpaper" android:fragment="com.android.settings.WallpaperTypeSettings" />
        <com.sonymobile.settings.preference.IntentPreference android:icon="@drawable/ic_lighteffects" android:title="@string/light_effects_settings_title" android:key="light_effects" settings:dependOnIsValidIntent="true" settings:after="theme">
            <intent android:targetPackage="com.sonymobile.settings.illumination" android:action="android.intent.action.MAIN" android:targetClass="com.sonymobile.settings.illumination.IlluminationSetting" />
        </com.sonymobile.settings.preference.IntentPreference>
        <com.sonymobile.settings.preference.IntentPreference android:icon="@drawable/homescreen_application_launcher" android:key="lockscreen" settings:dependOnIsValidIntent="true" settings:hasMetaData="true">
            <intent android:action="com.sonyericsson.settings.intent.action.LOCKSCREEN" />
        </com.sonymobile.settings.preference.IntentPreference>
    </com.sonymobile.settings.preference.PreferenceCategory>
    <com.sonymobile.settings.preference.PreferenceCategory android:title="@string/systemuipref_title">
        <com.sonymobile.settings.preference.IntentPreference android:icon="@drawable/ic_systemui1" android:key="quicksettings" settings:dependOnIsValidIntent="true" settings:hasMetaData="true">
            <intent android:action="com.sonymobile.intent.action.TOOLBAR_SETTINGS" />
        </com.sonymobile.settings.preference.IntentPreference>
        <com.sonymobile.settings.preference.IntentPreference android:icon="@drawable/ic_systemui2" android:key="power_toggles" settings:dependOnIsValidIntent="true" settings:hasMetaData="true">
            <intent android:action="com.serajr.powertoggles.preferences.intent.PREFERENCES" />
        </com.sonymobile.settings.preference.IntentPreference>
    </com.sonymobile.settings.preference.PreferenceCategory>
</PreferenceScreen>


To Add these Apps/shortcuts to the submenu you just created,refer this guide [Tutorial] How to add any App/Option in Settings.apk by saqib nazm
Just use the new maddy_settings.xml to link your new apps/actions.

6.Open smali/com/android/settings/ and add a new file named Maddy.smali

paste this code in it

Code:
Select Code
.class public Lcom/android/settings/Maddy;
.super Lcom/android/settings/SettingsPreferenceFragment;
.source "Maddy.java"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 17
    invoke-direct {p0}, Lcom/android/settings/SettingsPreferenceFragment;-><init>()V

    return-void
.end method


# virtual methods
.method public onCreate(Landroid/os/Bundle;)V
    .locals 1
    .parameter "savedInstanceState"

    .prologue
    .line 21
    invoke-super {p0, p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V

    .line 23
    const v0, 0x7f050054

    invoke-virtual {p0, v0}, Lcom/android/settings/Maddy;->addPreferencesFromResource(I)V

    .line 24
    return-void
.end method
Find and replace "Maddy" with your smali name.
Smali names should always start with Capital Letters.

Also note the Hex code you added in Step 5.
replace 0x7f050054 with your Hex value.



7.Recompile your Apk and Done!



Note:
Should work with any versions of Xperia.
Also may work on other Devices,Please try and report.

Credits:

Saqib nazm : For teaching me all this!
DbcCabuslay : For Smali ideas
Jishnu Sur™ : For some Advice

Hit Thanks and Rate Good if you find it helpful and Motivate
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental



The Following 23 Users Say Thank You to Madaditya For This Useful Post: [ Click to Expand ]
 
Saqib Nazm
Old
#2  
Saqib Nazm's Avatar
Forum Moderator / Recognized Themer
Thanks Meter 7699
Posts: 2,892
Join Date: Oct 2012
Location: Dhaka

 
DONATE TO ME
Great guide, very nicely explained and elaborated I hope this will help lots of users
The Following User Says Thank You to Saqib Nazm For This Useful Post: [ Click to Expand ]
 
Madaditya
Old
#3  
Madaditya's Avatar
Recognized Themer - OP
Thanks Meter 962
Posts: 936
Join Date: Jul 2012
Location: No where
Quote:
Originally Posted by saqib nazm View Post
Great guide, very nicely explained and elaborated I hope this will help lots of users
Thank you sir,for teachin me all this.
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental



The Following User Says Thank You to Madaditya For This Useful Post: [ Click to Expand ]
 
vishal_android freak
Old
#4  
vishal_android freak's Avatar
Recognized Developer / Recognized Contributor
Thanks Meter 4610
Posts: 1,684
Join Date: Dec 2012
Location: Mumbai
Good stuff.. glad to see you going ahead slowly..

Sent from my Nexus 5 using Tapatalk

My ROMs

| Pure Xperia HD, Official Carbon Rom 4.4.2, Unofficial Omni Rom 4.4.2, AOKP-4.4.2, Unofficial HellKat 4.4.2, Carbon Rom 4.3.1, Dark Xperia |

My Guides and Tools

| All in one drivers guide for ubislate tabs, CWM recovery for a13 tabs |

My kernel

| Super Fusion kernel for all HDPI devices |

Devices I Support

| All 2011 Xperias , Xperia M , Lg p760 and p765, Xperia Tipo, Xperia L |
The Following User Says Thank You to vishal_android freak For This Useful Post: [ Click to Expand ]
 
Aman_Arora
Old
#5  
Aman_Arora's Avatar
Senior Member
Thanks Meter 731
Posts: 664
Join Date: Jan 2013
Location: New Delhi
Keep going Good work All the Best !

Sent from my Nexus 5 using Tapatalk
Hit Thanks If this Post Helped You
Leader of

My Work:-

Visit My Android Blog at www.androexpert.blogspot.in Its new many more things to come up
The Following User Says Thank You to Aman_Arora For This Useful Post: [ Click to Expand ]
 
BDFreak
Old
#6  
BDFreak's Avatar
Recognized Themer
Thanks Meter 1361
Posts: 396
Join Date: Jan 2013
Location: Mymensingh
Useful guide. Keep sharing this kind of stuffs.
Having problem deodexing files? Or want a user friendly deodexer?
Download : Ultimate Deodexer

Do you have lots of apps scattered all over your pc?
Download : Apk File Manager

Are you having problem in Decompiling/Recompiling framework-res.apk?
Download : Advanced ApkTool
The Following User Says Thank You to BDFreak For This Useful Post: [ Click to Expand ]
 
Madaditya
Old
#7  
Madaditya's Avatar
Recognized Themer - OP
Thanks Meter 962
Posts: 936
Join Date: Jul 2012
Location: No where
Quote:
Originally Posted by vishal_android freak View Post
Good stuff.. glad to see you going ahead slowly..

Sent from my Nexus 5 using Tapatalk
Thank you!
Yes,the word slowly is so very important

Quote:
Originally Posted by Aman_Arora View Post
Keep going Good work All the Best !

Sent from my Nexus 5 using Tapatalk
Quote:
Originally Posted by BDFreak View Post
Useful guide. Keep sharing this kind of stuffs.
Thank you Aman and Bd
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental



The Following User Says Thank You to Madaditya For This Useful Post: [ Click to Expand ]
 
Jishnu Sur™
Old
#8  
Account currently disabled
Thanks Meter 7462
Posts: 2,453
Join Date: Nov 2012
Location: ND-BL-MB-KL

 
DONATE TO ME
Very good guide. Simple but very detailed. Better than many of the clustered one's! Congratulations..Keep up the good work!
The Following User Says Thank You to Jishnu Sur™ For This Useful Post: [ Click to Expand ]
 
knightzero07
Old
#9  
Member
Thanks Meter 4
Posts: 47
Join Date: Sep 2013
Nice guide I was looking for something like this just this day.
Is it the same when adding sub menu inside another header like device_info_settings.xml?
The Following User Says Thank You to knightzero07 For This Useful Post: [ Click to Expand ]
 
Madaditya
Old
(Last edited by Madaditya; 1st May 2014 at 05:13 AM.)
#10  
Madaditya's Avatar
Recognized Themer - OP
Thanks Meter 962
Posts: 936
Join Date: Jul 2012
Location: No where
Quote:
Originally Posted by Jishnu Sur™ View Post
Very good guide. Simple but very detailed. Better than many of the clustered one's! Congratulations..Keep up the good work!
Thank you Jishnu

Quote:
Originally Posted by knightzero07 View Post
Nice guide I was looking for something like this just this day.
Is it the same when adding sub menu inside another header like device_info_settings.xml?
This one is only for adding sub menus in main settings
For sub menu in device info,try studing "status" or "legal info" inside About to get an idea of how its referenced

Sent from my MT27i using Tapatalk
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental




Tags
add, edit, header, settings.apk
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes