[One (M7) Android Development] Hero:
What's up everyone, adding apps to the settings menu seems to have been really popular as of recently so here's a tutorial on adding apps to the settings menu for Sense 5. Normally, you would just have to modify XML code in settings_headers.xml like in previous Sense versions and other OEMs, but as of recent, HTC likes to put everything in java code...

So let's get to it :)

PART 1

First off, we are going to modify the app you want to add to the settings menu. I will use my app called "Axis Tweaks" as an example. So decompile the app, open up the AndroidManifest.xml, and look for the following line:

package="com.axis.tweaks"

Now that you found the name of the package, you will need to change this code:

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

to this:

NOTE:

The blue part will vary depending on the name of the package.

<intent-filter>
<action android:name="[COLOR="Blue"]com.axis.tweaks[/COLOR].action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

That's all we need to do with your app so recompile it. You also need to sign the app because you just modified the AndroidManifest.xml.

PART 2

Now we're going to decompile Settings.apk. This is where the majority of the work happens. After you decompile Settings.apk, navigate to res/values/ids.xml

Add the following id:

<item type="id" name="axis_tweaks">false</item>

Now, navigate to res/values/strings.xml and add the following line:

<string name="axis_tweaks">Tweaks</string>

Now, navigate to res/values/drawable-xxhdpi and drop in a PNG file. I called mine: ic_settings_axis_tweaks.png

After all that, recompile Settings.apk and immediately decompile your new Settings.apk

PART 3

In your new Settings.apk, navigate to smali/com/android/settings/framework/activity and open HtcGenericEntryProvider.smali

Add the green section to this file:

invoke-static {v2, v3, p1}, Lcom/android/settings/framework/activity/HtcGenericEntryProvider;->addWrapHeader(Lcom/android/settings/framework/activity/HtcWrapHeader;FLcom/android/settings/framework/activity/HtcWrapHeaderList;)Z

invoke-static {}, Lcom/android/settings/framework/activity/HtcWrapHeaderInfo;->getTransferMyStuff()Lcom/android/settings/framework/activity/HtcWrapHeader;
[COLOR="SeaGreen"]
move-result-object v2

add-int/lit8 v0, v1, 0x1

int-to-float v3, v1

invoke-static {v2, v3, p1}, Lcom/android/settings/framework/activity/HtcGenericEntryProvider;->addWrapHeader(Lcom/android/settings/framework/activity/HtcWrapHeader;FLcom/android/settings/framework/activity/HtcWrapHeaderList;)Z

invoke-static {}, Lcom/android/settings/framework/activity/HtcWrapHeaderInfo;->getTweaks()Lcom/android/settings/framework/activity/HtcWrapHeader;[/COLOR]

move-result-object v2

add-int/lit8 v1, v0, 0x1

Save that file and now open HtcWrapHeaderInfo.smali

Locate this method:

.method static getTransferMyStuff()Lcom/android/settings/framework/activity/HtcWrapHeader;

Add this new method right under that one:

[COLOR="SeaGreen"].method static getTweaks()Lcom/android/settings/framework/activity/HtcWrapHeader;
.locals 4

new-instance v0, Lcom/android/settings/framework/activity/HtcWrapHeader;

invoke-direct {v0}, Lcom/android/settings/framework/activity/HtcWrapHeader;-><init>()V

sget-object v1, Lcom/android/settings/framework/activity/HtcWrapHeader$Type;->NORMAL:Lcom/android/settings/framework/activity/HtcWrapHeader$Type;

iput-object v1, v0, Lcom/android/settings/framework/activity/HtcWrapHeader;->type:Lcom/android/settings/framework/activity/HtcWrapHeader$Type;

iget-object v1, v0, Lcom/android/settings/framework/activity/HtcWrapHeader;->info:Lcom/htc/preference/HtcPreferenceActivity$Header;

const-wide/32 v2, [COLOR="blue"]0x7f0802bc # id[/COLOR]

iput-wide v2, v1, Lcom/htc/preference/HtcPreferenceActivity$Header;->id:J

iget-object v1, v0, Lcom/android/settings/framework/activity/HtcWrapHeader;->info:Lcom/htc/preference/HtcPreferenceActivity$Header;

const v2, [COLOR="blue"]0x7f0201cb # drawable[/COLOR]

iput v2, v1, Lcom/htc/preference/HtcPreferenceActivity$Header;->iconRes:I

iget-object v1, v0, Lcom/android/settings/framework/activity/HtcWrapHeader;->info:Lcom/htc/preference/HtcPreferenceActivity$Header;

const v2, [COLOR="blue"]0x7f0b1078 # string[/COLOR]

iput v2, v1, Lcom/htc/preference/HtcPreferenceActivity$Header;->titleRes:I

iget-object v1, v0, Lcom/android/settings/framework/activity/HtcWrapHeader;->info:Lcom/htc/preference/HtcPreferenceActivity$Header;

new-instance v2, Landroid/content/Intent;

const-string v3, "android.intent.action.MAIN"

invoke-direct {v2, v3}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

const-string v3, "[COLOR="Blue"]com.axis.tweaks.action.MAIN[/COLOR]"

invoke-virtual {v2, v3}, Landroid/content/Intent;->setAction(Ljava/lang/String;)Landroid/content/Intent;

move-result-object v2

iput-object v2, v1, Lcom/htc/preference/HtcPreferenceActivity$Header;->intent:Landroid/content/Intent;

const-string v1, "[COLOR="blue"]axis[/COLOR]"

iput-object v1, v0, Lcom/android/settings/framework/activity/HtcWrapHeader;->anchor:Ljava/lang/String;

invoke-static {}, Lcom/android/settings/framework/app/HtcSettingsApplication;->getApplication()Landroid/app/Application;

move-result-object v1

invoke-virtual {v0, v1}, Lcom/android/settings/framework/activity/HtcWrapHeader;->prepareExtraInfo(Landroid/content/Context;)V

return-object v0
.end method[/COLOR]

The parts in BLUE are unique to you and you must change them accordingly. You can find your hex values in res/values/public.xml.

Example (all hex strings are in public.xml):

0x7f0802bc # id ----------------------------- locate the hex string for the ID you set for your app
0x7f0201cb # drawable ------------------- locate the hex string for the PNG you set for your app
0x7f0b1078 # string ------------------------ locate the hex string for the string you set for your app

com.axis.tweaks.action.LAUNCH ---- replace with what you added to the Manifest
axis ---------------------------------------------- rename this to whatever you want

You are done! Thanks chrisch