Reputation: 5113
I have this case where in our in-house app is capturing all the applications used by the user, and uploads the list to our cloud server, where I need to categorize them by the "category" at play store.
It would have been better if the android code could also find the category of an application by its package name, but looks like my developers were having problem doing this at the android end.
How do we find out the category of an application by using just its package name?
Upvotes: 3
Views: 947
Reputation: 12181
Yes, there seems to be a way:
Since you already found the names of the application packages.
You can use this unofficial googleplay api to get the info you need about the app.
Upvotes: 1
Reputation: 5113
Lets just pick one of the package name say "com.facebook.katana", and lets google it.
the first result (if its a valid android app) would be the play url like - https://play.google.com/store/apps/details?id=com.facebook.katana, lets hit this url and look at the source of it.
a span like this has what we need -
<span itemprop="genre">Social</span>
Now lets write a dirty index game in php to get the genre or category of our package, i hope y'all find it easy to understand, coz it ain't rocket science
the code is available here https://gist.github.com/brijrajsingh/6915711 and is given below as well.
Note - I would also suggest that once you have got a category for a package name you better store it in some db or memcache, so you don't need to hit it again and again for diff packages, also the code might stop running if you bombard the google servers, so go easy on it.
<?php
class PackageCategory
{
protected static $playurl = 'https://play.google.com/store/apps/details?id=';
public function PackageCategory($packageName) {
$this->packageName = $packageName;
}
public function getPackageCategory()
{
$result = $this->makeRequest(self::$playurl.$this->packageName);
//starting index of category tag
$indexstart = strpos($result,"<span itemprop=\"genre\">");
//ending index of category tag
$indexend = strpos($result,"</span>",$indexstart);
$category = substr($result,$indexstart+23,$indexend - ($indexstart+23));
echo $category;
}
//curl to the play store
/**
* Makes request to AWIS
* @param String $url URL to make request to
* @return String Result of request
*/
protected function makeRequest($url) {
//echo "\nMaking request to:\n$url\n";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
if (count($argv) < 2) {
echo "Usage: $argv[0] PackageName\n";
exit(-1);
}
else {
$packageName = $argv[1];
}
$packageCategory = new PackageCategory($packageName);
$packageCategory->getPackageCategory();
?>
Upvotes: 3