Skip to content

Commit ee03f9b

Browse files
authored
Merge pull request #44 from aeharding/fix-getname
Fix getName() on Android
2 parents 1ba8a9b + c3dbd20 commit ee03f9b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

android/src/main/java/com/mycompany/plugins/example/AppIconBase.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
import android.app.Activity;
1212
import android.content.Context;
13+
import android.content.Intent;
1314
import android.util.Log;
1415
import android.content.ComponentName;
1516
import android.content.pm.PackageManager;
1617

1718
public class AppIconBase {
1819

1920
private Activity activity;
21+
private Context context;
2022
private List<String> disableIconNames = new ArrayList<String>();
2123
private String activeIconName = "";
2224
private String packageName;
@@ -25,6 +27,8 @@ public class AppIconBase {
2527

2628
public AppIconBase(Activity activity, Context context) {
2729
this.activity = activity;
30+
this.context = context;
31+
2832
this.packageName = context.getPackageName();
2933
pm = context.getApplicationContext().getPackageManager();
3034
activeIconName = "";
@@ -35,9 +39,11 @@ public Boolean isSupported() {
3539
}
3640

3741
public String getName() {
38-
ComponentName componentName = new ComponentName(this.activity, this.activity.getClass());
42+
Intent intent = pm.getLaunchIntentForPackage(context.getPackageName());
43+
ComponentName componentName = intent.getComponent();
3944
int status = pm.getComponentEnabledSetting(componentName);
40-
if (status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
45+
46+
if (status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || status == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
4147
// The component is currently enabled
4248
String name = componentName.getShortClassName();
4349
if (Objects.equals(name, ".MainActivity")) {

0 commit comments

Comments
 (0)