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
Related
I'm wondering if it's feasible to list out all Twitter clients that are installed into a phone. At first, I thought this could be done by matching the package name with "Twitter". But most of the Twitter clients on Android don't have 'Twitter' name in their package name.
We can fetch application list with specific permissions but that doesn't going to help me. Fetching applications with certain custom intents probably not going to help as well, and I still have to find a way to get a list of applications that handle a custom Intent.
It doesn't seem feasible but there must be some way that could at least put me close to want I want. Anyone would like to shed some light on it?
I don't know if there is some kind of method to get "twitter client" (how we define Twitter client?).
You can fetch a list of names (the twitter clients you know) on the packages installed on devices.
final List<PackageInfo> apps = context.getPackageManager().getInstalledPackages(0);
final String separator = ";";
final String separatorVersion = "-";
//Log.i("Package list", "num:+"+apps.size());
for (PackageInfo infoApp : apps) {
for (TwitterClient tr : mapTwitterClient.values()) {
if (infoApp.packageName.contains(tr.getPackageName()) ) { //it's a Twitter client this package?
if (!twitterClients.equals("")) {
twittersClients += separator;
}
twitterClients += tr.getCommonName()+separatorVersion+infoApp.versionName;
}
}
}
You need to create the class TwitterClient which just have 2 properties(packageName and commonName) and his getters/setters.
And fill map with all TwitterClient you know (Ex: new TwitterClient("com.twitter.android","Twitter official") );
private static final HashMap<String, TwitterClient> mapTwitterClient
This method it's hard process so use smartly.
I want to implement a listview showing android applications with their internet usage. Fir this, first i have to list all the apps, i have done this using PackageManager, like this:
packageManager = getPackageManager();
List<PackageInfo> packageList = packageManager
.getInstalledPackages(PackageManager.GET_META_DATA);
apkList = (ListView) findViewById(R.id.applist);
apkList.setAdapter(new ApkAdapter(this, packageList, packageManager));
But this code lists all system apps as well like : Android Sytem, Calculator,Calender, Status Bar, Live Wallpapers etc. which doesnt look appropriate. I tried to filter system apps using:
/*To filter out System apps*/
for(PackageInfo pi : packageList) {
boolean b = isSystemPackage(pi);
if(!b) {
packageList1.add(pi);
}
}
But then the code displays only installed apps, like whatsapp, tango, foursquare etc. It does not show apps like gmail, facebook, browser,maps.
Can anybody suggest how should i write the code that only displays list of application that actually use the internet. Thanks in advance!
I want to implement a listview showing android applications with their
internet usage.
An anybody suggest how should i write the code that only displays list
of application that actually use the internet
One solution (maybe only one that works best and came to my head) is to use TrafficStats class that calculating data (TCP, UDP) transferred through network. Exactly in your case, you need to get data for each UID (each application has own UID).
All what you need to know if application trasfered more that zero bytes through network and when you know that, you can tell that "this application uses network".
Here is pseudo-code you could use:
List<Application> collection = new ArrayList<Application>();
Application app = null; // some custom object is good approach
PackageManager pm = getActivity().getPackageManager();
for (ApplicationInfo info: pm.getInstalledApplications(
PackageManager.GET_META_DATA)) {
// received data by application
long downloaded = TrafficStats.getUidRxBytes(info.uid);
// transmitted data by application
long uploaded = TrafficStats.getUidTxBytes(info.uid);
// filter system applications only
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// check if application has network usage
if (downloaded > 0 || uploaded > 0) {
// it's application you want
}
}
// non-system application
else {
if (downloaded > 0 || uploaded > 0) {
// it's application you want
}
}
}
It's important to say that TrafficStats is available from API 8 and also Before JELLY_BEAN_MR2, this may return unsupported on devices where statistics aren't available. I used this approach and never had a problems.
Note: Also I want to mention that maybe there are another possible approach(es) for example reading from some system files but this is (at least for me) hardcoded approach and i don't recommend to use it (also in various devices files can be on different places, have different content and different filename).
I hope it will help you solve your problem.
Application use internet will need Internet Permission
You can filter out those app by checked PackageInfo.permission
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);
}
}
Hi I want to get a list of all of the installed applications on the users device I have been googling for the longest time but can't find what i want this link was the closest though and works fine except me being new don't understand how to use the method getPackages(); and create a list with it
http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon
Any help on how to create the actual list would be a major help i have all that code already in just can't get the list to actually show thanks for any help
I was working on something like this recently. One thing I'll say up front is to be sure and perform this in a separate thread -- querying the application information is SLOW. The following will get you a list of ALL the installed applications. This will include a lot of system apps that you probably aren't interested in.
PackageManager pm = getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);
To limit it to just the user-installed or updated system apps (e.g. Maps, GMail, etc), I used the following logic:
List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();
for(ApplicationInfo app : apps) {
//checks for flags; if flagged, check if updated system app
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
installedApps.add(app);
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
//Discard this one
//in this case, it should be a user-installed app
} else {
installedApps.add(app);
}
}
EDIT: Also, to get the name and icon for the app (which is probably what takes the longest -- I haven't done any real deep inspection on it -- use this:
String label = (String)pm.getApplicationLabel(app);
Drawable icon = pm.getApplicationIcon(app);
installedApps should have a full list of the apps you need, now. Hope this helps, but you may have to modify the logic a bit depending on what apps you need to have returned. Again, it is SLOW, but it's just something you have to work around. You might want to build a data cache in a database if it's something you'll be accessing frequently.
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)