List of just installed apps - android

I need to store all the installed apps icons in an array, and names in another array, so I´ve this code:
List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
int numberApps = apps.size();
String[] appsNames = new String[numberApps];
Drawable[] appsIcons = new Drawable[numberApps];
for(int i=0;i<apps.size();i++) {
PackageInfo p = apps.get(i);
String pname = p.packageName;
String appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
appsNames[i] = appname;
Drawable appicon = p.applicationInfo.loadIcon(getPackageManager());
appsIcons[i] = appicon;
}
And it works, the problem is that all the apps are displayed, even the system ones, so now i need to change the code for getting just the ones installed or updated by the user. I´ve been searching and I´ve found this and this, but as i´m using a Drawable and string array, and I cannot change that, I don´t know how to make it work.
Can someone help me please??

I made a overkill solution for my university some weeks ago: you can have a look at this class on Github.
We were dealing with Android Security Flow, so I do not think it is trivial to get what the app is about but the class suits perfectly your needs.
You would need to invest a bit of time to bind it to your app because it is designed to be asynchronous but it would work. There are probably simpler options though (but who likes it when it's too simple?)
The options you found would work but why are you stuck to an array, can't you create an adapter of it??

Related

How to organize apps into folders in Android Programming?

I'm developing a launcher application. I want to auto organize apps into folders with subjects as Game, Social Network, Entertainment, Tool... But I do not know based on the information of the application to know what type it.
Sample : http://dantri4.vcmedia.vn/tI0YUx18mEaF5kMsGHJ/Image/2014/07/APUS-Launcher-3-feb4a.jpg
As far as I know there is no straightforward way to achieve that.
The only thing that I could think about is to try to find some key words in the labels name of the apps.
Something like that:
private ArrayList<PackageInfo> searchPackageForString(PackageManager pm, String find){
List<PackageInfo> packs = pm.getInstalledPackages(0);
ArrayList<PackageInfo> results = new ArrayList<>();
for (PackageInfo pi : packs) {
if(pi.applicationInfo.loadLabel(pm).toString().toLowerCase().contains(find)){
results.add(pi);
}
}
return results;
}
Then you could try something like That:
searchPackageForString(getPackageManager(), "game");
I didn't try it but I thing that this is the only possibly direction.
Of course I can be wrong...
Edit:
Now that I looked in the pic you attached, I think that they check by find apps respond to Intents for action.
here some example:
https://stackoverflow.com/a/28404480/3332634

Android: Determine category of installed apps

Given the list of installed packages on an Android device, is there a way to sort the applications into categories without using a self-compiled hard-coded list of apps in categories?
For example, if the installed apps were Phone, Angry Birds & Messages, Phone & Messages might be in Communications and Angry Birds in Games.
I've seen How to get Category for each App on device on Android? yet hoped there may be a method that has come along since.
No, because apps don't have categories. Apps don't need to be installed through google play, the categories on other stores won't be the same. It may never have been installed from a store to begin with- I sideload apps all the time written by myself or friends. Th concept doesn't exist.
Not to mention Google Play categories are pretty bad- things frequently don't fall into one or the other, the descriptions are vague, and they're way too broad- they need at least 2 or 3 levels of subcategories to make them halfway usable.
There is no change API wise since the last question.
At best, you could retrieve each package name and scrape the Google Play page. However, this will fail if the app is not present on Google Play.
I also faced the same issue. The solution for the above query is stated below.
Firstly, download the Jsoup library or download the jar file.
or Add this to your build.gradle(Module: app) implementation 'org.jsoup:jsoup:1.11.3'
private class FetchCategoryTask extends AsyncTask {
private final String TAG = FetchCategoryTask.class.getSimpleName();
private PackageManager pm;
#Override
protected Void doInBackground(Void... errors) {
String category;
pm = getPackageManager();
List<ApplicationInfo> packages =
pm.getInstalledApplications(PackageManager.GET_META_DATA);
Iterator<ApplicationInfo> iterator = packages.iterator();
// while (iterator.hasNext()) {
// ApplicationInfo packageInfo = iterator.next();
String query_url = "https://play.google.com/store/apps/details?
id=com.imo.android.imoim"; //GOOGLE_URL + packageInfo.packageName;
Log.i(TAG, query_url);
category = getCategory(query_url);
Log.e("CATEGORY", category);
// store category or do something else
//}
return null;
}
private String getCategory(String query_url) {
try {
Document doc = Jsoup.connect(query_url).get();
Elements link = doc.select("a[class=\"hrTbp R8zArc\"]");
return link.text();
} catch (Exception e) {
Log.e("DOc", e.toString());
}
}
}
In return, you will get Application Company Name and category of the application

How to detect if an android app is a game?

In an app I am developing I need to iterate through the installed apps and detect which ones are games. Is there any way to do this?
I was thinking to a Play Store API that can search for package name and returns its category even if it's only limited to apps on the store. Does something similar exist? Would it be possible?
Is there any alternative way to do it?
This answer is deprecated!
Correct and backwards compatible way to do this is here!
Since Android API version 21, there's finally a way to check if an application is a game.
PackageManager pm = mContext.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(mPackageName,0);
if((ai.flags & ApplicationInfo.FLAG_IS_GAME) == ApplicationInfo.FLAG_IS_GAME)
return true;
return false;
There is no automatical way to detect if an app is a game. You just could compaire the package name of the common part of the package name. My solution was to index the google store pages and hash the package names.
I could optimize my hashes by building common prefixes. I handled the package name as a domain and grep the public suffix. I use the list from http://publicsuffix.org/.
A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are .com, .co.uk and pvt.k12.ma.us. The Public Suffix List is a list of all known public suffixes.
The Public Suffix List is an initiative of Mozilla, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.
With this list you can detect part of a packagename is a common prefix.
For me the above answer didn't work, the ApplicationInfo.FLAG_IS_GAME is now deprecated, with API 28+ (in my case), you can do something like this:
_pm = _context.PackageManager;
List<string> packageList = new List<string>();
Intent intent = new Intent(Intent.ActionMain);
intent.AddCategory(Intent.CategoryLeanbackLauncher); // or add any category you want
var list = _pm.QueryIntentActivities(intent, PackageInfoFlags.MetaData);
foreach (var app in list)
{
ApplicationInfo ai = _pm.GetApplicationInfo(app.ActivityInfo.PackageName, 0);
var allFlags = ai.Flags;
if (allFlags.HasFlag(ApplicationInfoFlags.IsGame))
{
packageList.Add(app.ActivityInfo.PackageName);
}
}

how do I know where my application comes from?

I need your help. I have two questions !
1) How can I know where an application I download comes from? Google Play or others.
I use something like that to get some informations about installed packages; but I didn't found the way to get where a package come from ! http://myandroidStore.com/myNewGame.apk for exemple.
List<PackageInfo> packages = getActivity() .getPackageManager()
.getInstalledPackages(0);
for (int i=0; i<packages.size(); i++) {
PackageInfo packageInfo = packages.get(i);
AppList tmpList = new AppList();
tmpList.applicationName = packageInfo.applicationInfo.loadLabel(getActivity()
.getPackageManager()).toString();
tmpList.packageName = packageInfo.packageName;
tmpList.versionName = packageInfo.versionName;
tmpList.versionCode = packageInfo.versionCode;
tmpList.provider = packageInfo.providers;
tmpList.firstInstallTime = packageInfo.firstInstallTime;
tmpList.lastUpdateTime = packageInfo.lastUpdateTime;
tmpList.signatures = packageInfo.signatures;
}
2) When "Unknown Sources" isn't selected I can't download application beyond Google Play.
Do you have an idea how Android check this verification?
1) How can I know where an application I download comes from? Google Play or others.
AFAIK the system provides no means for you to get this information. If you are interested in obtaining it you'd have to make seperate apk files with something unique embedded in them, that way you'd know based on that unique string where the apk came from at runtime.
2) When "Unknown Sources" isn't selected I can't download application beyond Google Play. Do you have an idea how Android check this verification?
I assume that the PackageManager is what is making the check for this. Not certain though.

get information of app in android

hello expert,
i want to get information of all apk in mobile, like name,icon,date etc....
i refer check it but there are not satisfied solution. so can you help me?
From your activity you should call
List<ApplicationInfo> applications = getPackageManager().getInstalledPackages(0);
Then you can get the information by running though the applications list.
You can check http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstalledApplications(int) for more info on the falgs you can use.
If you want the icon and install/update of an application you should instead use
List<PackageInfo> applications = getPackagerManager().getInstalledPackages(0);
This will give you a list of PackageInfos. Then you can acces the information you seek:
for(PackageInfo info : applications){
Drawable icon = info.applicationInfo.loadIcon(getContext());
long firstInstalled = info.firstInstallTime;
long lastUpdate = info.lastUpdateTime;
}
Checkout http://developer.android.com/reference/android/content/pm/PackageInfo.html to see what else you can get from the packageinfo.
In addition to the above answer,
You should also have a look at http://developer.android.com/reference/android/os/Build.html.
It holds various informations regarding the cellphone (or tablet)

Categories

Resources