2010-12-14 5 views
8

Android 마켓이Android 마켓 또는 Google Apps의 패키지 이름은 무엇입니까?

 /* 
    * Test for existence of Android Market 
    */ 
    boolean androidMarketExists = false; 
    try{ 
     ApplicationInfo info = getPackageManager() 
          .getApplicationInfo("com.google.process.gapps", 0); 
     //application exists 
     androidMarketExists = true; 
    } catch(PackageManager.NameNotFoundException e){ 
     //application doesn't exist 
     androidMarketExists = false; 
    } 

처럼 설치되었는지 확인해야합니다. com.google.process.gapps가 안드로이드 마켓을 가지고 있는지 여부는 알 수 없습니다.

답변

19

com.android.vending (내 Galaxy S)에서, market : // URI를 처리하는 사람을 쿼리하여 알아내는 더 좋은 방법입니다.

Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.setData(Uri.parse("market://search?q=foo")); 
    PackageManager pm = getPackageManager(); 
    List<ResolveInfo> list = pm.queryIntentActivities(intent, 0); 

목록에 하나 이상의 항목이있는 경우 마켓이 있습니다.

+0

내가 진짜 패키지에 foo를 변경해야합니까? – jax

+5

나는 이것에 완전히 동의하지 않는다. 전화와 관련이없는 다른 마켓 애플 리케이션이있을 수 있으며 이것들은 market : // intents를 처리 할 수있다. 특별히 Google의 마켓 앱을 확인해야하는 경우 패키지 관리자의 com.android.vending을 어떻게 든 확인해야 할 수도 있습니다. – greg7gkb

1

이 코드는 바로 바로 아래에 수정 사소한 변경

체크 아웃 코드를 필요로한다 :

boolean androidMarketExists = false; 
    try{ 
     ApplicationInfo info = getPackageManager().getApplicationInfo("com.android.vending", 0); 
     if(info.packageName.equals("com.android.vending")) 
      androidMarketExists = true; 
     else 
      androidMarketExists = false; 
    } catch(PackageManager.NameNotFoundException e){ 
     //application doesn't exist 
     androidMarketExists = false; 
    } 
    if(!androidMarketExists){ 
     Log.d(LOG_TAG, "No Android Market"); 
     finish(); 
    } 
    else{ 
     Log.d(LOG_TAG, "Android Market Installed"); 
    } 
관련 문제