I wan that my app should show a list of games installed on user device. Is it possible to that?
One way I think is that I will tell the user to create a folder on desktop suppose named "gamesforXYZapp". Now is it possible that my app will search for this folder and show the games put in that folder in my app?
Is there any other way?
In Android, you cannot set your app as "Game Type" so you cannot filter applications by this category.
I think, a solution to this would be to find all games packages from Google Play and put that list in your app and frequently update it. It needs uninterrupted internet connection so that you could send found apps list to server and server will return back games from that list. So, you need to write server code for that.
If you have a list of 'All Games' on the Platform (like A--C does), you could use the PackageManager to determine which apps are installed on the users device, and then match that list to the 'All Games' list.
This might look something like this:
List<String> allGames = //list of all games on device - not sure where you get this
PackageManager packageManager = getPackageManager();
List<ApplicationInfo> appsList;
appsList = new ArrayList<ApplicationInfo>();
appsList = packageManager.getInstalledApplications(0);
Iterator<ApplicationInfo> it = appsList.iterator();
while (it.hasNext()) {
if (appName != null) {
ApplicationInfo value = (ApplicationInfo) it.next();
if (value != null) {
String appName2 = value.packageName;
if (appName2 != null) {
// Check if this app is in the 'All Games' list
if (allGames.contains(appName2) {
// This is a game
}
}
}
}
Related
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
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
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);
}
}
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.
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.