Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download App from Google Play programmatically

I need to download a few Apps from google play for analysis purpose. But I don't want to do it manually (I have to do it often and each time the Apps that I want to download change!).

So, the question is, whether I can write a program to download the Apps or not. If it is possible, how?

I have seen this plugin for chrome: http://codekiem.com/2012/02/24/apk-downloader/ but I cannot trust the author (the App requires google user and pass and device ID) and have decide to implement my own program.

like image 253
Arash Avatar asked Jun 05 '13 04:06

Arash


1 Answers

For those of you who are looking for a Java implementation, here it is:

Top level Steps:

  1. gather gmail ID, password, Android ID, and security token from your phone
  2. download the jar file for the crawler implemented by Akdeniz
  3. download the source file for googleplay.java (cli) from Akdeniz
  4. modify the googleplay.java
  5. put it all together :D

Detailed Steps:

  1. Gmail ID and password are obvious! For Android ID follow the demirozali and use "getAndroidID" function. I could not make "getAuthToken" work! Therefore I used toxicbakery to get security token. Note that the function "updateToken" (which actually gets you the security token) should be called in an AsyncTask not on UI Thread.

  2. From Akdeniz github site download the "googleplaycrawler-0.1-SNAPSHOT.jar" file.

  3. I couldn't make use of "GooglePlayAPI" class in the jar file. So I decided to change the CLI version. The CLI class in "googleplaycrawler-0.1-SNAPSHOT.jar" is called "googleplay.java" which can be downloaded from the source files.

  4. Rename "googleplay.java" to "Changed_googleplay.java" and modify it. Such that the method "searchCommand()" returns a arrayList of String, rather than printing the result on console.

  5. Having done all the previous steps, create a project in jetBrains or ... and add "googleplaycrawler-0.1-SNAPSHOT.jar" as a library. Also, add "Changed_googleplay.java" to your src directory. Finally use the following method in your application. You can use the following class to search a query and then download all Free Apps corresponding to that query.

    public void SearchAndDownload() {
        String login = "[email protected]";
        String password = "xxxx";
        String androidId = "xxxx";
        String securitytoken = "xxxx";
        String command = "search";
        String query = "Maps";
        String offest = "0";
        String number = "5";
    
        Changed_googleplay gp = new Changed_googleplay();
        ArrayList<String> res = gp.operate(new String[]{"-i", androidId, "-e", login, "-p", password, "-t", securitytoken, command, "-o", offest, "-n", number, query});
    
        res.remove(0);
        if (command.equals("search")) {
            System.out.println("Title"+"\t"+"Package Name"+"\t"+"Price"+"\t"+"Number of Downloads");
            for (String line : res){
                String[] split = line.split(Changed_googleplay.DELIMETER);
                String name = split[0];
                String packageName = split[1];
                String creator = split[2];
                String price = split[3];
                String size = split[4];
                String dlNO = split[5];
                if(price.equals("Free")){
                    System.out.println(name+"\t"+packageName+"\t"+price+"\t"+dlNO);
                    gp.operate(new String[]{"-i", androidId, "-e", login, "-p", password, "-t", securitytoken, "download", packageName});
                }
            }
        }
    }
    

You may want to take a look at the list of command line options in the crawler project main page.

have fun!

like image 70
Arash Avatar answered Nov 04 '22 12:11

Arash