-2
ActivityInfo[] list
    = getPackageManager().getPackageInfo(getPackageName()).activities;

This gives me the list of all Activities, but how to find out which activity is the main Activity?


I guess Im making a mistake,Im new to android, please correct me

       PackageManager p = getPackageManager();
       Intent intent = p.getLaunchIntentForPackage("com.example.launcherhiddenapp");
       ComponentName componentName = new ComponentName(this, String.valueOf(intent));
       p.setComponentEnabledSetting(componentName, 
       PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

This is not working, my app is visible in launcher and I can launch it as asusually

This is my code after I used intent

       PackageManager p = getPackageManager();
       Intent intent = p.getLaunchIntentForPackage(getPackageName());
       ComponentName componentName = new 
       ComponentName(this,String.valueOf(intent));
       p.setComponentEnabledSetting(componentName, 
       PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 
       PackageManager.DONT_KILL_APP);

It is still not working, app is visible in launcher, Please help me anyone

Amir
  • 15
  • 5
  • When you say "main Activity", do you mean the launcher activity? – Ajeeli May 04 '20 at 12:09
  • Does this answer your question? [android - how to find the name of the main activity of an application?](https://stackoverflow.com/questions/5964735/android-how-to-find-the-name-of-the-main-activity-of-an-application) – dt170 May 04 '20 at 12:15
  • Im making an app where it gets list of installed apps with checkboxes, if user clicks a checkbox, that particular app has to hide from launcher in non rooted mobile, so i need the ComponentName of that app, it has 2 parameters package name and mainactivity class name, we can get the package name of any other app in my app, using ActivityInfo I can get the list of all activities of other app, but how do I find out the mainactivity name? @Ajeeli – Amir May 04 '20 at 13:00
  • yes the first activity that opens up as application start @Ajeeli – Amir May 04 '20 at 13:09
  • Replace "com.example.launcherhiddenapp" with "packageName" – Ajeeli May 05 '20 at 08:17
  • Intent intent = p.getLaunchIntentForPackage(packageName) – Ajeeli May 05 '20 at 08:18
  • How can system recognise that packageName, it says cannot resolve symbol packageName! @Ajeeli – Amir May 05 '20 at 08:21
  • Intent intent = p.getLaunchIntentForPackage(getPackageName()) – Ajeeli May 05 '20 at 08:28
  • @Ajeeli, mam "com.example.launcherhiddenapp" is my package name, To check out whether it works fine or not, Im trying to hardcode the package name. But in my actual app, I have to have the package name of the other apps in launcher which is to be hidden – Amir May 05 '20 at 08:29
  • I think you need to edit your original question to be more clear and obvious about what you actually need. – Ajeeli May 05 '20 at 08:32
  • yes mam sorry about that I have modified my question accordingly, please help me @Ajeeli – Amir May 05 '20 at 08:51

1 Answers1

0

Try this:

PacketManager manager = getPackageManager();
Intent intent = manager.getLaunchIntentForPackage(getPackageName());

This should give you the full package name of the main activity

Ajeeli
  • 325
  • 1
  • 3
  • 16
  • No its not working, PackageManager p = getPackageManager(); ComponentName componentName = new ComponentName(this, com.example.launcherhiddenapp.MainActivity.class); p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); In this code Im trying to hide my own app icon in launcher, I can get the component name, for other apps how will I get the component name. ComponentName requires 2 things, a packagename which we can get, other is Mainactivity.class name which is difficult to get.How will I get this. – Amir May 04 '20 at 13:53