0

I need to log the launcher Activity name for a particular activity in android.

I have tried using the code given in " Get the launcher Activity name of an android application" by doing few modifications like .. 1) I have created a Class called as launcherActivity. 2) In that class I have created a method called as getLauncherActivity(). 3) When I try to call this method in another class it is showing null Object reference.

public class LauncherActivity {

    public String getLauncherActivity(Context context){
        PackageManager packageManager = context.getPackageManager();
        Intent intent = packageManager.getLaunchIntentForPackage(context.getPackageName());
        return null;
    }
}

I am calling this method has

String launcheractivity=launcherActivity.getLauncherActivity(ctx);

What all changes I need to do to log this launcheractivity name. So please do give Suggestions...

Thank You in Advance:)

Nikunj
  • 3,937
  • 19
  • 33
padma
  • 15
  • 6

2 Answers2

0

First of all, activity doesn't have a launcher activity. An application have launcher activity. If you want to know the name of all the launcher activity of all apps installed in your phone. Then you can get it by code here

Insane Developer
  • 1,014
  • 10
  • 19
0

This should be what you need.

public String getLauncherActivity(Context context){
        PackageManager packageManager = context.getPackageManager();
        Intent intent =    packageManager.getLaunchIntentForPackage(context.getPackageName());
        String lname=intent.getComponent().getClassName();
        Log.e("luncher",lname);
        return lname;
kfir88
  • 380
  • 2
  • 16
  • if i write this code in separate class .then i need to call this method from another class sooo first do i need to create a private Context ctx . Then use String LauncherActivity=launcheractivity.getLauncherActivity(ctx);.Is this correct? – padma Mar 06 '18 at 09:26
  • but i am getting null object reference – padma Mar 06 '18 at 10:28
  • show me yours logs if you can and how the code of your class – kfir88 Mar 06 '18 at 10:30
  • show me yours logs if you can and the code of your class – kfir88 Mar 06 '18 at 10:31
  • can we call the method from anywhere in the program or do we need to follow some procedure to call method – padma Mar 06 '18 at 15:30
  • anywhere ou have valide context (Activity, Fragment , Service) or a way to get the context to pass to the method – kfir88 Mar 06 '18 at 16:14