getInstalledPackages() for Android multiple users - android

I want to get a list of all apps installed on my device. My code is below:
PackageManager pm = getApplicationContext().getPackageManager();
List<PackageInfo> list = pm.getInstalledPackages(0);
When I try multiple user registered on my device (i.e. Android for Work), the API returns a list from the same user space/managed profile, which makes sense.
My question is, is there an option to get a list of all apps from the device (like Settings - Apps - All apps), no matter where the app is installed?

Use LauncherApps (only can get apps will shown in launcher), you can see how Launcher3 use it
https://developer.android.com/reference/android/content/pm/LauncherApps.html

Related

How to detect if specific app can show ads

I am implementing an android application which checks whether an installed application can show ads or not.
What is the safest way to achieve this?
Thanks in advance.
Get All Applicaitons that are installed.
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
Check The Appstore using the app id to check if it has ads
Home Page For Apps: https://play.google.com/store/apps?hl=en
App Page: https://play.google.com/store/apps/details?id=com.bandainamcogames.dbzdokkanww&hl=en
just replace the id's value of com.bandainamcogames.dbzdokkanww with the app package from the packages list
then check the page for "Contains Ads"
Refs:
Get All Apps
An ad is an element from the Web. Every element loaded from the web is essentially a HTTP request. You could implement in your application some mechanism to check the HTTP requests generated in real time by other applications and block them.

Android How to get List of uninstalled apps from device

In my use case i want to access list of all uninstalled from device.
i tried this-
PackageManager pm = getPackageManager();
List<ApplicationInfo> applications = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
Log.d("pkg inofo->", appInfo.packageName);
but it is not working for me it is not return list of uninstalled app.
so my question is what is wrong with this code or any other approach to get list of uninstalled apps.
There is no way to get uninstalled apps.
But you can get list of uninstalled application after your app is installed.
You need to use <action android:name="android.intent.action.PACKAGE_REMOVED"/>, whenever any application is removed you can store it in your DB and get the list of uninstalled apps.

changing the list of applications in a custom launcher programmatically

i am working on this admin/user lockscreen application. What this application entails is that if the admin (to be identify by his pin/password) tries to unlock the screen, it gives the admin access to all applications installed on the phone, while other users (to be identify by his pin/password) tries to unlock the screen, it gives them access to specific applications. i have already both the lockscreen and launcher for my application. But i got stucked at how to handle the launcher for both admin and user.
Android does not allow switching launcher activities programmatically, so this idea is out of place. so i figured out that i need to programmatically refresh the list of installed application for user (non- admin) to pick only the specific authorised application by the admin. So my question is, how can i refresh list of installed application after the user unlocks the screen and pick only specific applications that will be shown to the user?
To obtain a list of all installed apps use PackageManager:
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
// check if app is suitable for the user
}

how to get reliable list of uninstalled packages android

I am getting list of packages using packagemanager with GET_UNINSTALLED_PACKAGES flag,
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
but since it returns: "information about all applications (even uninstalled ones) which have data directories." I am unable to get reliable list of previously uninstalled package including apps that didn't left a data directory behind.
Is there any way to achieve this?
Disclaimer : I didn't try this solution, but it may help (requires Android 5)
With android 5, there is this new API : UsageStatsManager with this method :
usageStatsManager.queryAndAggregateUsageStats(startTime,endTime)
returning an Map where keys are the package name (and values are usage statistics). Hopefully, this will include uninstalled apps (but I'm not sure !). Of course you won't get the AppInfo (only the package name)
Note also this important remark about required permissions:
NOTE: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.

How to find the package name of default settings application

I want to prevent launching of task manager and Settings applications in my application. For this, I tried to obtain currently running application and checked whether their package name is allowed or not .If it is not allowed then show a new activity.
When work out it is show that the package name of default android Settings application is com.android.settings. Now I have some doubts
Is the Settings application has package name com.android.settings in all android versions? If not, which are they?
How to find package name of Task Manager?
try this
private String querySettingPkgName() {
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfos == null || resolveInfos.size() == 0) {
return "";
}
return resolveInfos.get(0).activityInfo.packageName;
}
For this,I tried to obtain currently running application and checked whether their package name is allowed or not .If it is not allowed then show a new activity.
Fortunately, for the users affected by your app, this will be unreliable.
Is the Settings application has package name com.android.settings in all android versions?
Not necessarily. More importantly, any given firmware can have any number of applications that modify settings, supplied by the firmware author. Some settings can be modified even without being part of the firmware, particularly on rooted devices.
If not,which are they?
You are welcome to make a list of all device manufacturers and ROM mod authors and ask them that question.
How to find package name of Task Manager?
There are any number of "task manager" apps included in devices, ROM mods, and available on the Play Store and other distribution points. You are welcome to make a list of all of them and ask their authors that question.
shell into the device using adb, and invoke:
pm list packages
this will provide you a list of pacakges. from there you will should see:
com.android.settings
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d("Packages", "" + packageInfo.packageName);
}
above code should help you
It's not totally clear what is the scenario.
I guess it is something along the lines of showing off devices to public but not have them f'up the device for others.
Maybe it would be better to do a whitelist instead of a blacklist. Meaning the shop should state which apps should be testable on the devices and then you start your activity if it is any other.
But this again will need maintenance: package names of popular apps may also change. You better provide a way of updating the settings of your app via an online service so you can change the needed packages without physical access to the devices and without having to download and install the complete app.
If you just need a device that goes through many hands and should not be tempered with I suggest using a modified device. I only know of Sonim: they provide a library (needs a Sonim provided hash key in your manifest to use that). With it you can prohibit the altering of many settings without preventing access to the whole settings app.

Categories

Resources