dpc57092 2013-10-10 09:43
浏览 14
已采纳

获取Android应用程序的类别 - 在服务器端

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?

  • 写回答

2条回答 默认 最新

  • dongshan6870 2013-10-10 09:43
    关注

    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 "
    Making request to:
    $url
    ";
            $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
    ";
        exit(-1);
    }
    else {
        $packageName = $argv[1];   
    }
    
    $packageCategory = new PackageCategory($packageName);
    $packageCategory->getPackageCategory();
    
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究
  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理
  • ¥50 webrtc-streamer TCP rtsp
  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计