Usage of Application Info , Package Info and Resolve Info - android

What is the use of Application info and how to use it.
I'm confused how to retrieve the installed apps from the device and to display it with logo
Can anyone please help me to sort it out.
Differentiate the terms applicaiton info, package info and resolve info.

to display a list of installed apps, you can try this
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
You will get all the necessary data in the ResolveInfo to start a application. You can check ResolveInfo
or try this code
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>)
pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}

Related

Programmatically getting a list of all apps in an android device

How do I get a list of all apps in an android device,which includes the system apps,and the uninstalled apps in storage.
You can easily get all Applications installed on a device using this code :
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
The pkgAppsList has all the Apps which includes system and user apps
You can try out different methods as suggested in this link
List<ApplicationInfo> infos = getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
// create a list with sze of total number of apps
String[] apps = new String[infos.size()];
int i = 0;
// add all the app name in string list
for (ApplicationInfo info : infos) {
apps[i] = info.packageName;
i++;
}
Let me know if this helped you

how to check installed apps android

hey can anyone explain to me this if condition , btw the code works but i dont understand the if condition
PackageManager pm = context.getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}
To get the list of installed apps on Android, the code is used as follows:
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appsList = context.getPackageManager().queryIntentActivities(intent, 0);

How can I get OS default apps in android

I'm developing a launcher app, I need to retrieve an Android OS default Phone app, Browser app and SMS apps', application Info (Application name, Package name, Launcher icon). Following code is used to get all launchable applications.
private static List<ApplicationInfo> getInstalledApps(Context context, PackageManager pm) {
List<ApplicationInfo> installedApps = context.getPackageManager().getInstalledApplications(0);
List<ApplicationInfo> laughableInstalledApps = new ArrayList<>();
for(int i =0; i<installedApps.size(); i++){
if(pm.getLaunchIntentForPackage(installedApps.get(i).packageName) != null){
laughableInstalledApps.add(installedApps.get(i));
}
}
return laughableInstalledApps;
}
After spending some time with the code, I found a way get what I wanted.
Default Dial App
Intent mainIntent = new Intent(Intent.ACTION_DIAL, null);
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
List<ResolveInfo> pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
ActivityInfo info = pkgAppsList.get(0).activityInfo;
Default SMS App
String smsPkgName = Telephony.Sms.getDefaultSmsPackage(context);
ApplicationInfo info = getPackageManager().getApplicationInfo(smsPkgName, 0);
Default Browser App
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent,
PackageManager.MATCH_DEFAULT_ONLY);
ActivityInfo info = resolveInfo.activityInfo;
Try with PackageManager#getPreferredActivities(java.util.List, java.util.List, java.lang.String), where the first parameter is a list of IntentFilter, which you would like to get default apps for. Then the answer is written in list passed as second parameter.
Here are some common intents for which you might try to find default apps.

How to get metadata from ActivityInfo?

I want to read activity metadata from another app. I have cole like this:
PackageManager packageManager = getPackageManager();
Intent intent = new Intent(MY_ACTION);
List<ResolveInfo> pluginsInfo = packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
for (ResolveInfo plugin : pluginsInfo) {
ResolveInfo info = plugin;
ActivityInfo aInfo = info.activityInfo;
Bundle metadata = aInfo.metaData;
}
And sometimes it works good, but sometimes metadata is null. On same emulator and same app version. Is there other way to do this?
And answer is simple:
packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER | PackageManager.GET_META_DATA);

Android check if application package is launchable

I'm looking for the best way to check if application is launchable.
There is my code :
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if (packageManager.getLaunchIntentForPackage(p.applicationInfo.packageName) != null) {
// Get application info
}
}
This works, but when i do app profiling i noticed that packageManager.getLaunchIntentForPackage() method consumes a lot of execution time, so i'm looking for an alternative way to check if each application is launchable without getting the launch intent.
Any idea ?
Thank you !
I found solution for my own problem, i hope it will help someone :
PackageManager packageManager = context.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = packageManager.queryIntentActivities(
mainIntent, 0);
Collections.sort(apps, new ResolveInfo.DisplayNameComparator(
packageManager));
for (ResolveInfo resolveInfo : apps) {
// Get application data here
}

Categories

Resources