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;
}
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);
}
}
}
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.
I need to get the list of package info for application which has been installed as Device admin. The code you share should support from Adroid Api version 8.
The following code will give me the list of Downloaded apps info, but i need an extra filter in the list as the app should be Device admin enabled app
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 ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
Thanks in Advance
Here the solution :
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
List<ComponentName> activeAdmins = devicePolicyManager.getActiveAdmins();
if (activeAdmins != null){
for (ComponentName admin : activeAdmins){
admin.getPackageName();
}
}
We will get list of apps use this
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
}
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
}
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;
}