Here it is described, how to get a list of all installed apps on Android by using the PackageManager
.
I would like to get this complete list, filtered by all installed "Games". How can I filter all installed apps for category "Games"
Here it is described, how to get a list of all installed apps on Android by using the PackageManager
.
I would like to get this complete list, filtered by all installed "Games". How can I filter all installed apps for category "Games"
You need to parse each app web page to get its genre then sperate games genres from apps genres.
you could use Jsoup Java HTML Parser and here is a sample code
public class MainActivity extends AppCompatActivity {
public final static String GOOGLE_URL = "https://play.google.com/store/apps/details?id=";
public static final String ERROR = "error";
...
private class FetchCategoryTask extends AsyncTask<Void, Void, Void> {
private final String TAG = FetchCategoryTask.class.getSimpleName();
private PackageManager pm;
private ActivityUtil mActivityUtil;
@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 = GOOGLE_URL + packageInfo.packageName;
Log.i(TAG, query_url);
category = getCategory(query_url);
// store category or do something else
}
return null;
}
private String getCategory(String query_url) {
boolean network = mActivityUtil.isNetworkAvailable();
if (!network) {
//manage connectivity lost
return ERROR;
} else {
try {
Document doc = Jsoup.connect(query_url).get();
Element link = doc.select("span[itemprop=genre]").first();
return link.text();
} catch (Exception e) {
return ERROR;
}
}
}
}
}
you will find something like
<a class="r2Osbf" href="/store/apps/category/GAME_RACING" title="Racing">Racing</a>
...
"applicationCategory":"GAME_RACING"
So if the category contains "Game" text then it is a game.
Update: check this out