I am trying to make a program to get the names of all installed applications. In my Activity, I have a method called getApplicationNames
that should return this information:
private ArrayList<String> getApplicationNames(Context context){
ArrayList<String> nameOfRunningApps = new ArrayList<>();
List<ApplicationInfo> runningApplications = context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
for(ApplicationInfo applicationInfo: runningApplications){
nameOfRunningApps.add(applicationInfo.name);
}
return nameOfRunningApps;
}
Now I want to call this method in onCreate()
:
ArrayList<String> installedProgramNames = getApplicationNames(??);
How do I make an instance of Context
in order to call this method? Is this even possible?