I want to get a list of Installed apps, but only the ones which have an icon and are launchable. I am making a launcher app and using this:
private List<AppList> getInstalledApps() {
List<AppList> res = new ArrayList<AppList>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((isSystemPackage(p) == false)) {
String appName = p.applicationInfo.loadLabel(getPackageManager()).toString();
Drawable icon = p.applicationInfo.loadIcon(getPackageManager());
String package_name = p.applicationInfo.packageName;
res.add(new AppList(appName, package_name, icon));
}
}
private boolean isSystemPackage(PackageInfo pkgInfo) {
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true : false;
}
The problem is, to filter out non launchable apps, I have to filter out system apps, which is not the best solution because it also filters out these apps: Camera, Calendar, Calculator etc.
You can check if an app is launchable by
packageManager.getLaunchIntentForPackage(packageName) != null
For icons, you can check if
info.loadIcon(packageManager) != null.
Related
This is what I am trying to achieve.
Basically I want a sort of a dialog type pop-up window,
That displays a list of installed apps, with a button next to them.
This is for a custom launcher I'm working on, How would one go about doing this?
I'm looking for suggestions in what kind of direction I should start looking, And which android services would be optional to use in this case.
Here's the basics I use for finding specified apps I want in the list:
private ArrayList<AppDetail> getInstalledApps(boolean getSysPackages, String filter) {
ArrayList<AppDetail> res = new ArrayList<AppDetail>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue;
}
AppDetail newInfo = new AppDetail();
newInfo.name = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
if (newInfo.name.toLowerCase().contains(filter.toLowerCase())) {
if(!newInfo.name.toLowerCase().contains("launcher")) {
res.add(newInfo);
}
}
}
return res;
}
I am new to android programming.
I want to list all the process which uses/access certain resources like :
File(s)
Internet etc
Any sample code or suggestion.
Thanks in Advance ...:)
You will get all application name which is using internet,
private ArrayList<String> getInstalledAppsWithSpecificPermission(Context context) {
ArrayList<String> appsPkgName = new ArrayList<String>();
PackageManager pm = context.getPackageManager();
List<PackageInfo> appNamelist = pm.getInstalledPackages(0);
Iterator<PackageInfo> it = appNamelist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.d("System Application which using internet = ", ""+pk.applicationInfo.loadLabel(pm));
continue;
}
if (PackageManager.PERMISSION_GRANTED == pm
.checkPermission(Manifest.permission.INTERNET,
pk.packageName))
results.add("" + pk.applicationInfo.loadLabel(pm));
}
Log.v("Application using internet = ", appsPkgName.toString());
return results;
}
I am creating an android app which has the list of all the apps which user can access from its android phone menu.
Here is my code which is working successfully..
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;
// skip system apps if they shall not be included
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
continue;
}
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);
}
Now this gives me a big list and i can classify its items in 3 ways :
1st (Apps like): Speed Moto, Subway Surf, Chrome (Which i installed)
2nd (Apps like):Camera, Email, Messaging (Installed by Default)
3rd (.... Like):PageBuddyNotiSvc, Dialer Storage etc (Some Packages)
Now i want to filter the 3rd type of Apps and want to keep only 1st and 2nd type..
How can i achieve this list..
You can get the information about each application using the following code
ApplicationInfo app = context.getPackageManager().getApplicationInfo(packageName, 0);
//And then check the dir
if (app.sourceDir.startsWith("/data/app/")) {
//Non-system app
}
else {
//System app
}
I have to detect programatically weither google apps and google services are installed on a device or not.
A first solution is to use the packagemanager :
private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.google.vending";
void someMethod() {
packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
googlePlayStoreInstalled = true;
break;
}
}
}
But is there something more reliable ?
I find an other way in testing the result of a market intent
PackageManager pm = getPackageManager();
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=dummy"));
List<ResolveInfo> list = pm.queryIntentActivities(market, 0);
if (list != null && list.size() > 0)
mMarketInstalled = true;
else
mMarketInstalled = false;
What do you think about this solution ?
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;
}