Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an App category from play store by its package name in Android?

Tags:

java

android

I want to fetch the app category from play store through its unique identifier i.e. package name, I am using the following code but does not return any data. I also tried to use this AppsRequest.newBuilder().setAppId(query) still no help. Thanks.

                String AndroidId = "dead000beef";
                MarketSession session = new MarketSession();
                session.login("email", "passwd");
                session.getContext().setAndroidId(AndroidId);

                String query = "package:com.king.candycrushsaga";
                AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(0)
                        .setEntriesCount(10).setWithExtendedInfo(true).build();

                session.append(appsRequest, new Callback<AppsResponse>() {
                    @Override
                    public void onResult(ResponseContext context, AppsResponse response) {

                        String response1 = response.toString();
                        Log.e("reponse", response1);

                    }
                });
                session.flush();
like image 600
Ishant Sagar Avatar asked Feb 04 '15 12:02

Ishant Sagar


People also ask

How do I find out the category of an app?

Best way to search is to search for packagename and you can get the category in return.

How do I launch an app using package name?

Just use these following two lines, so you can launch any installed application whose package name is known: Intent launchIntent = getPackageManager(). getLaunchIntentForPackage("com. example.

How do I find my Google Play package name?

One method to look up an app's package name is to find the app in the Google Play app store using a web browser. The package name will be listed at the end of the URL after the '? id='.


2 Answers

Use this script:

######## Fetch App names and genre of apps from playstore url, using pakage names ############# 
"""
Reuirements for running this script:
1. requests library
Note: Run this command to avoid insecureplatform warning pip install --upgrade ndg-httpsclient
2. bs4

pip install requests
pip install bs4
"""

import requests
import csv
from bs4 import BeautifulSoup

# url to be used for package
APP_LINK = "https://play.google.com/store/apps/details?id="
output_list = []; input_list = []

# get input file path
print "Need input CSV file (absolute) path \nEnsure csv is of format: <package_name>, <id>\n\nEnter Path:"
input_file_path = str(raw_input())

# store package names and ids in list of tuples
with open(input_file_path, 'rb') as csvfile:
    for line in csvfile.readlines():
        (p, i) = line.strip().split(',')
        input_list.append((p, i))


print "\n\nSit back and relax, this might take a while!\n\n"

for package in input_list:

    # generate url, get html
    url = APP_LINK + package[0]
    r = requests.get(url)

    if not (r.status_code==404):
        data = r.text
        soup = BeautifulSoup(data, 'html.parser')

        # parse result
        x = ""; y = "";
        try:
            x = soup.find('div', {'class': 'id-app-title'})
            x = x.text
        except:
            print "Package name not found for: %s" %package[0]

        try:
            y = soup.find('span', {'itemprop': 'genre'})
            y = y.text
        except:
            print "ID not found for: %s" %package[0]

        output_list.append([x,y])

    else:
        print "App not found: %s" %package[0]

# write to csv file
with open('results.csv', 'w') as fp:
    a = csv.writer(fp, delimiter=",")
    a.writerows(output_list)
like image 95
aliasav Avatar answered Oct 19 '22 23:10

aliasav


This is what i did, best and easy solution

https://androidquery.appspot.com/api/market?app=your.unique.package.name  

Or otherwise you can get source html and get the string out of it ...

https://play.google.com/store/apps/details?id=your.unique.package.name  

Get this string out of it - use split or substring methods

<span itemprop="genre">Sports</span>  

In this case sports is your category

like image 31
Salmaan Avatar answered Oct 20 '22 00:10

Salmaan