2013-05-24 4 views
5

私は、すべてのアプリケーションがこのコードを使用してデバイスをインストールしてフェッチしていたアプリケーションで働いています:Androidでプログラマティックにアプリのカテゴリを取得しますか?

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
mainIntent.addCategory("com.myapp.MY_CATEGORY"); 
final List<ResolveInfo> pkgAppsList =getPackageManager().queryIntentActivities(mainIntent, 0); 

は今、私はカテゴリにアプリケーションをしたい異なりそのカテゴリーによります。私に提案してください。

+0

これからアイデアを取ってください。 https://support.google.com/googleplay/android-developer/answer/113475?hl=en –

+1

あなたは 'addCategory()'関数を使ってカテゴリを追加していますので、それらの場所を保存することはできません値。 –

+1

@ Sam-In-TechValensは、市場に出回っているアプリをリストするためのカテゴリです。インテントカテゴリはまったく違う獣です。 – FoamyGuy

答えて

2

アプリケーションのカテゴリを知るには、Google Playからデータを取得する必要があります。 android-market-apiを確認することができます。それはサードパーティのAPIです。その情報

  • に応じてあなたが望む任意のキャリアまたはロケールで市場を閲覧することができます。
  • キーワードまたはパッケージ名を使用してアプリを検索してください。
  • アプリIDを使用してアプリ情報を取得します。
  • アプリIDを使用してコメントを取得します。
  • あなたはこのAPIを使用して、カテゴリの情報を解析することができますのであれば、あなたがより良いチェックPNGのスクリーンショットやアイコン

を取得します。

0

私はこれらのライブラリを使用して、いくつかのアプリのカテゴリを収集するために、AsyncTaskを実現:

  • アンドロイド・マーケット-API-0.6

  • com.google.protobuf 2.4.1

このリンクで見つけることができます:

https://code.google.com/archive/p/android-market-api/downloads

http://mvnrepository.com/artifact/com.google.protobuf/protobuf-java

はここでdoInBackgroundのコードだ()メソッド:

 final ArrayList<MarketApplication> results = new ArrayList<>(); 
     AccountManager am = AccountManager.get(MainActivity.this.getBaseContext()); 
     Account[] accounts = am.getAccountsByType("com.google"); 
     if (accounts.length > 0) { 
      try { 
       AccountManagerFuture<Bundle> accountManagerFuture = 
         am.getAuthToken(accounts[0], "android", null, MainActivity.this, null, 
           null); 
       Bundle authTokenBundle = accountManagerFuture.getResult(); 
       String authToken = 
         authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN).toString(); 

       MarketSession session = new MarketSession(); 
       session.setAuthSubToken(authToken); 

       Market.AppsRequest appsRequest = Market.AppsRequest.newBuilder() 
         .setQuery(params[0]) 
         .setStartIndex(0).setEntriesCount(10) 
         .setWithExtendedInfo(true) 
         .build(); 


       session.append(appsRequest, new MarketSession.Callback<Market.AppsResponse>() { 
        public void onResult(Market.ResponseContext context, Market.AppsResponse 
          response) { 
         for (int i = 0; i < response.getEntriesCount(); i++) { 
          MarketApplication marketApplication = new MarketApplication(); 
          Market.App app = response.getApp(i); 
          marketApplication.setName(app.getTitle()); 
          Market.App.ExtendedInfo extendedInfo = app.getExtendedInfo(); 
          marketApplication.setCategory(extendedInfo.getCategory()); 
          results.add(marketApplication); 
         } 
        } 
       }); 
       session.flush(); 
      } catch (Exception e) { 
       System.out.println(e.getMessage()); 
      } 
     } 
     return results; 

カテゴリー情報は、ExtendedInfoからだ、とアプリケーションの名前は、カスタムクラスMarketApplicationに追加されます。 params[0]は、興味のあるアプリ名のようなクエリ文字列です。 特定のクエリを作成する開発者を支援wikiページがあります:このサービスは、Androidマニフェストでこれらの権限を追加するために必要であることを

https://code.google.com/archive/p/android-market-api/wikis/HowToSearchApps.wiki

テイク予告:

<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission> 
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission> 
<uses-permission android:name="android.permission.INTERNET"></uses-permission> 
関連する問題