As a safety measure I would like to get the list of apps that aren't installed from the Play Store. Is there a way to do this?
The packageManager contains a method getInstalledApplications but I don't know which flags to add to get the list. Any help would be appreciated.
Edit: Here is an code example of v4_adi's answer.
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
if (packageManager.getInstallerPackageName(packInfo.packageName) == null)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
This is a good start, however this also returns a lot off pre-installed Android and Samsung apps. Is there anyway to remove them from the list? I only want user installed apps from unknown sources.
The following link has answer to your question
The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.
How to know an application is installed from google play or side-load?
Originally I thought it would be enough to retrieve the apps that weren't installed via the Google Play Store. Later I found that I also needed to filter out the pre-installed system applications.
I found the last part of the puzzle in another post: Get list of Non System Applications
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
boolean hasEmptyInstallerPackageName = packageManager
.getInstallerPackageName(packageInfo.packageName) == null;
boolean isUserInstalledApp = (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0;
if (hasEmptyInstallerPackageName && isUserInstalledApp)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
Related
Several games and apps show adds like install the app to get rewards. How does that function? Can I get the list of all the apps that user has installed on his device including uninstalled apps, how?
You can get list of installed non-system apps
public void installedApps() {
List<PackageInfo> packList = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++) {
PackageInfo packInfo = packList.get(i);
if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
String appName = packInfo.applicationInfo.loadLabel(getPackageManager()).toString();
Log.e("App № " + Integer.toString(i), appName);
}
}
}
This question has been asked before:
How to get list of ALL apps (including System Apps)?
However, when I called getPackageManager().getInstalledPackages(0), it did not return all the apps. For example, the following apps were not found by this call: com.google.android.music, com.google.android.youtube, com.google.earth, com.google.android.gm.
Is it because they are part of Google Mobile Service?
Code:
public static List<ApplicationInfo> getInstalledAppInfos(Context context) {
final PackageManager packageManager = context.getPackageManager();
return packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
}
Test:
List<ApplicationInfo> apps = getInstalledAppInfos(this);
for (int i = 0; i < apps.size(); i++) {
Log.d(TAG, "App( " + i + ") " + apps.get(i).packageName);
}
Im working on a app where I want to present the user with all installed apps and let him/her choose one and then do something with it. I followed a tutorial (this: http://impressive-artworx.de/2011/list-all-installed-apps-in-style/ ) although I'm having some issues. After following the tutorial I only got apps that weren't preinstalled (like all background apps that aren't launchable) which is great if you want the apps that the user has downloaded from the play store. The problem is that in my app I want to display the launchable system apps like Youtube and Browser but not the non-launchable ones like Search Application Provider.
Here's the code that I'm using when to get the apps:
private List<App> loadInstalledApps(boolean includeSysApps) {
List<App> apps = new ArrayList<App>();
// the package manager contains the information about all installed apps
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
CharSequence description = p.applicationInfo.loadDescription(packageManager);
app.setDescription(description != null ? description.toString() : "");
apps.add(app);
}
return apps;
}
Now my question is; what is the best way to filter out the non-launchable apps?
Any help is appreciated!
The Best way is:
public static List<ApplicationInfo> getAllInstalledApplications(Context context) {
List<ApplicationInfo> installedApps = context.getPackageManager().getInstalledApplications(PackageManager.PERMISSION_GRANTED);
List<ApplicationInfo> launchableInstalledApps = new ArrayList<ApplicationInfo>();
for(int i =0; i<installedApps.size(); i++){
if(context.getPackageManager().getLaunchIntentForPackage(installedApps.get(i).packageName) != null){
//If you're here, then this is a launch-able app
launchableInstalledApps.add(installedApps.get(i));
}
}
return launchableInstalledApps;
}
How to get exactly "Unknown Sources" application list on Android?
what is flag to used? If it is not this method,what are others method? and
How to programmically?
PackageManager pm = this.getPackageManager();
final List<PackageInfo> appinstalled = pm
.getInstalledPackages(what is flag??); //
Sorry for my bad English.
Thank you.
Someone else may have a better solution, but here's the best I could come up with...
Iterate through all installed packages, comparing each one against a known "good" package that has a good signature, with checkSignatures(int, int) or checkSignatures(String, String). If the return value of checkSignatures is SIGNATURE_UNKNOWN_PACKAGE, then you've got a package from an unknown source.
Otherwise, it doesn't look like any of the flags to getInstalledPackages are intended to filter for unknown sources.
I know this is an old post but I think the following answer might help you:
https://stackoverflow.com/a/42248268/2212770
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
boolean hasEmptyInstallerPackageName = packageManager.
getInstallerPackageName(packageInfo.packageName) == null;
boolean isUserInstalledApp = (packageInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) == 0;
if (hasEmptyInstallerPackageName && isUserInstalledApp)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
How can I get the list of installed third-party applications on Android phone.
I am able to get the list of application with the code below but I want only third-party applications.
PackageManager pm = context.getPackageManager();
appInstalModel.setAppName(p.applicationInfo.loadLabel(context.getPackageManager()).toString());
appInstalModel.setAppPkg(p.packageName);
appInstalModel.setAppVersionName(p.versionName);
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for (int i=0; i < apps.size(); i++)
{
if ((apps.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 1)
{
//System app
}
}
RoflcoptrException's answer is correct. But in some cases it won't give you all the installed third-party applications. ApplicationInfo also has flag FLAG_UPDATED_SYSTEM_APP which is set
If this application has been install as an update to a built-in system
application
On my smart phone such applications include Amazone Kindle, Adobe Reader, Slacker Radio and others. These applications did not come with the phone and were installed from Google Play Store. Thus, they can be considered as third-party apps.
So, you may also want to check FLAG_UPDATED_SYSTEM_APP flag.
final PackageManager packageManager = _context.getPackageManager();
List<ApplicationInfo> installedApplications =
packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo appInfo : installedApplications)
{
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
{
// IS A SYSTEM APP
}
if ((appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)
{
// APP WAS INSTALL AS AN UPDATE TO A BUILD-IN SYSTEM APP
}
}
The ApplicationInfo object will have the FLAG_SYSTEM flag unset. The sdmove program might have some sample code.
small changes in #Roflcoptr answer.
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for (int i=0; i < apps.size(); i++)
{
if ((apps.get(i).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
{
//System app
}
}
Thanks #Roflcoptr for your answer.
public static List<PackageInfo> getInstalledAppList(Context context) {
ArrayList<PackageInfo> packList = (ArrayList<PackageInfo>) context.getPackageManager().getInstalledPackages(0);
showLog("/n/n ********************** App List ********************");
for (int i = 0; i < packList.size(); i++) {
PackageInfo packInfo = packList.get(i);
if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
String appName = packInfo.applicationInfo.loadLabel(context.getPackageManager()).toString();
showLog(appName + "(" + packInfo.packageName + ")");
} else {
packList.remove(i);
i--;
}
}
showLog("List Size : " + packList.size());
showLog("/n/n ********************** END ********************");
return packList;
}