Skip to content

Commit

Permalink
feat(android): change app icons at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Dec 22, 2024
1 parent 48871ce commit c7d2a36
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,9 @@ AndroidBuilder.prototype.validate = function validate(logger, config, cli) {
try {
if (cli.tiapp.android && cli.tiapp.android.manifest) {
this.customAndroidManifest = AndroidManifest.fromXmlString(cli.tiapp.android.manifest);

// check if we have <activity-alias> nodes
this.activityAliasCount = this.customAndroidManifest.xmlDomDocument.getElementsByTagName('application')[0].getElementsByTagName('activity-alias').length;
}
} catch (ex) {
logger.error(__n('Malformed <manifest> definition in the <android> section of the tiapp.xml'));
Expand Down Expand Up @@ -3522,7 +3525,8 @@ AndroidBuilder.prototype.fetchNeededManifestSettings = function fetchNeededManif
const neededSettings = {
queries: neededQueriesDictionary,
storagePermissionMaxSdkVersion: storagePermissionMaxSdkVersion,
usesPermissions: Object.keys(neededPermissionDictionary)
usesPermissions: Object.keys(neededPermissionDictionary),
skipLauncher: this.activityAliasCount > 0
};
return neededSettings;
};
Expand Down Expand Up @@ -3619,7 +3623,8 @@ AndroidBuilder.prototype.generateAndroidManifest = async function generateAndroi
storagePermissionMaxSdkVersion: neededManifestSettings.storagePermissionMaxSdkVersion,
packageName: this.appid,
queries: neededManifestSettings.queries,
usesPermissions: neededManifestSettings.usesPermissions
usesPermissions: neededManifestSettings.usesPermissions,
skipLauncher: this.activityAliasCount > 0
});
const mainManifest = AndroidManifest.fromXmlString(mainManifestContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import org.appcelerator.titanium.proxy.RProxy;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

@Kroll.module(parentModule = AppModule.class)
Expand Down Expand Up @@ -61,6 +63,20 @@ public ActivityProxy getTopActivity()
}
}

@Kroll.method
public void changeIcon(String oldPackage, String newPackage)
{
String pkgName = TiApplication.getInstance().getPackageName();
TiApplication.getInstance().getPackageManager().setComponentEnabledSetting(
new ComponentName(pkgName, pkgName + "." + oldPackage),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
);
TiApplication.getInstance().getPackageManager().setComponentEnabledSetting(
new ComponentName(pkgName, pkgName + "." + newPackage),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP
);
}

@Kroll.getProperty
public int getAppVersionCode()
{
Expand Down
2 changes: 2 additions & 0 deletions android/templates/build/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
android:alwaysRetainTaskState="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<% if (!skipLauncher) { %>
<category android:name="android.intent.category.LAUNCHER" />
<% } %>
</intent-filter>
</activity>

Expand Down

0 comments on commit c7d2a36

Please sign in to comment.