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

Was it Helpful?

  • Yes!

    Votes: 38 88.4%
  • No.

    Votes: 5 11.6%

  • Total voters
    43
Search This thread

treantprotector

Senior Member
Jan 26, 2013
197
17
Struga
did you click on start button? :D
or did you give it root access? :D

I dont know what tje problem could really be because removing Launcher line worked just fine but whenever i want to remove somerhing from About Phone menu like Changelog or something i cannot open About Phone because i get system.apk has stopped. Maybe i should remove something else and not just the lines as im removing now... :(
 
Jan 31, 2015
26
2
every thing is diffrent in cm 12.1 whit your Tutorial

Hi Geeks :cool:

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

LDer69G.png


add this line

Code:
 <header android:icon="[COLOR="Brown"]@drawable/ic_settings_maddy[/COLOR]" android:id="[COLOR="SeaGreen"]@id/maddy_settings[/COLOR]" android:title="[COLOR="Purple"]@string/maddy_settings[/COLOR]" android:fragment="[COLOR="DarkOrange"]com.android.settings.Maddy[/COLOR]" />

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:
 <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" />


Hit Thanks and Rate Good if you find it helpful and Motivate :good:

hi
i use this method for CM12.1 but in res/xml there is no file like "settings_headers.xml" but i dont give up and search all of XLM file so i find some thing that i think in android 5.1.1 has been renamed to "dashboard_categories.xml"
and i do this on it ( is attached ) i have also found "ids.xml" in address "C:\AdvancedApkTool\3-Out\Settings.apk\res\values" (that have different address whit your Tutorial.

i done this thing. do i do right? or something wrong? you know... in dashboard_categories.xml the codes was changed and there is no more"
" <header android:icon="@drawable/ic_settings_about" "
and changed to " dashboard-category " and " <dashboard-tile "

can you update you Tutorial??
 

Attachments

  • dashboard_categories.txt
    9.6 KB · Views: 62
Thanks For Awesome Thread But I Face Errors In Recomoiling. It Gives Error In The Smali File We Created! Any Help?

hi
i use this method for CM12.1 but in res/xml there is no file like "settings_headers.xml" but i dont give up and search all of XLM file so i find some thing that i think in android 5.1.1 has been renamed to "dashboard_categories.xml"
and i do this on it ( is attached ) i have also found "ids.xml" in address "C:\AdvancedApkTool\3-Out\Settings.apk\res\values" (that have different address whit your Tutorial.

i done this thing. do i do right? or something wrong? you know... in dashboard_categories.xml the codes was changed and there is no more"
" <header android:icon="@drawable/ic_settings_about" "
and changed to " dashboard-category " and " <dashboard-tile "

can you update you Tutorial??
Is it damn needed to quote always the entire OP ?
Please edit it !!
 

ajiththiruvatta

Senior Member
Jan 24, 2014
295
260
28
Kottayam
Smali error

Any help bud? :( Its 5.0.2 lolipop based rom
Logs here:
I: Using Apktool 2.0.2
I: Smaling smali folder into classes.dex...
..\_WorkArea6\_working\Settings.apk\smali\com\android\settings\Batdroid.smali[21,4] Error for input '.parameter': Invalid directive
..\_WorkArea6\_working\Settings.apk\smali\com\android\settings\Batdroid.smali[21,15] mismatched input '"savedInstanceState"' expecting END_METHOD_DIRECTIVE
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file: com/android/settings/Batdroid.smali
at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:71)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:55)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:41)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:378)
at brut.androlib.Androlib.buildSources(Androlib.java:305)
at brut.androlib.Androlib.build(Androlib.java:288)
at brut.androlib.Androlib.build(Androlib.java:261)
at brut.apktool.Main.cmdBuild(Main.java:225)
at brut.apktool.Main.main(Main.java:84)

----------------

Recompile Not Successful!
 

ajiththiruvatta

Senior Member
Jan 24, 2014
295
260
28
Kottayam
Smali Error Fixed

Any help bud? :( Its 5.0.2 lolipop based rom
Logs here:
I: Using Apktool 2.0.2
I: Smaling smali folder into classes.dex...
..\_WorkArea6\_working\Settings.apk\smali\com\android\settings\Batdroid.smali[21,4] Error for input '.parameter': Invalid directive
..\_WorkArea6\_working\Settings.apk\smali\com\android\settings\Batdroid.smali[21,15] mismatched input '"savedInstanceState"' expecting END_METHOD_DIRECTIVE
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file: com/android/settings/Batdroid.smali
at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:71)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:55)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:41)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:378)
at brut.androlib.Androlib.buildSources(Androlib.java:305)
at brut.androlib.Androlib.build(Androlib.java:288)
at brut.androlib.Androlib.build(Androlib.java:261)
at brut.apktool.Main.cmdBuild(Main.java:225)
at brut.apktool.Main.main(Main.java:84)

----------------

Recompile Not Successful!


The smali syntax mentioned in the main thread is of 1.5.x format, while apktool 2.0.x requires the newer syntax.
@Madaditya please edit OP

Step 6 edit for Lolipop Roms/newest apk tool:

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

paste this code in it
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
    .param p1, "savedInstanceState"    # Landroid/os/Bundle;

    .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
 
  • Like
Reactions: moonryder

Top Liked Posts

  • There are no posts matching your filters.
  • 48
    Hi Geeks :cool:

    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

    LDer69G.png


    add this line

    Code:
     <header android:icon="[COLOR="Brown"]@drawable/ic_settings_maddy[/COLOR]" android:id="[COLOR="SeaGreen"]@id/maddy_settings[/COLOR]" android:title="[COLOR="Purple"]@string/maddy_settings[/COLOR]" android:fragment="[COLOR="DarkOrange"]com.android.settings.Maddy[/COLOR]" />

    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:
     <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)


    azyhAVc.jpg


    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:
    <item type="id" name="maddy_settings">false</item>

    klwBw9c.jpg


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

    Open strings.xml and add this code

    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'

    Pm9FxLF.jpg


    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:
    <public type="xml" name="[I]somethig_something[/I]" id="[COLOR="Blue"]0x7f050053[/COLOR]" />

    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:
    <public type="xml" name="maddy_settings" id="[COLOR="Red"]0x7f050054[/COLOR]" />

    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.

    NB0fgHy.jpg


    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:
    <?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:
    .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, [COLOR="Blue"]0x7f050054[/COLOR]
    
        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.

    iiisBqs.jpg


    7.Recompile your Apk and Done!

    a9nIkuH.png


    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 :good:
    4
    Hello,

    I found how to modify the error.

    Code:
    .class public Lcom/android/settings/Cpu;
    .super Lcom/android/settings/SettingsPreferenceFragment;
    .source "Cpu.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
       [COLOR="Red"] .param p1, "savedInstanceState"    # Landroid/os/Bundle;[/COLOR]
    
        .prologue
        .line 21
        invoke-super {p0, p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V
    
        .line 23
        const v0, 0x7f050065
    
        invoke-virtual {p0, v0}, Lcom/android/settings/Cpu;->addPreferencesFromResource(I)V
    
        .line 24
        return-void
    .end method


    Thank you again for the guide
    2
    Great guide, very nicely explained and elaborated :good: I hope this will help lots of users
    2
    Great guide, very nicely explained and elaborated :good: I hope this will help lots of users

    Thank you sir,for teachin me all this.
    2
    bro this linl is dead if u have v1.5.2 pls upload for me.

    .

    Can't you use Google?

    Envoyé de mon C6603 en utilisant Tapatalk