如果你在Android Market上发布了程序,怎么通过程序访问,查看程序的信息呢?谷歌大神为我们提供了--An open-source API for the Android Market,另外,也给Ruby和PHP都留了接口,当然了访问是需要Google帐户滴,更多信息请看考:http://code.google.com/p/android-market-api/

OK,废话少说,That's it!

Current progress

  • You can browse market with any carrier or locale you want.
  • Search for apps using keywords or package name.
  • Retrieve an app info using an app ID.
  • Retrieve comments using an app ID.
  • Get PNG screenshots and icon

Requirement:

需要把这两个JAR导入项目中,由于很好理解,代码就不加注释了 :-)

HowToSearchApps  :

You can search by package using :

  1. String query = "pname:<package>"

By developper name :

  1. String query = "pub:<name>"
  1. String query = "pname:com.luckyxmobile.timers4me";// 通过包名查找程序
  2. MarketSession session = new MarketSession();  
  3. session.login("your gmail account""your password");  
  4. AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(0).setEntriesCount(10).setWithExtendedInfo(true).build();  
  5. session.append(appsRequest, new MarketSession.Callback<AppsResponse>() {  
  6. @Override 
  7. public void onResult(ResponseContext context, AppsResponse response) {  
  8. TextView text = (TextView) findViewById(R.id.text);  
  9. String id = response.getApp(0).getId();  
  10. String creatorID = response.getApp(0).getCreatorId();  
  11. String creator = response.getApp(0).getCreator();  
  12. String packageName = response.getApp(0).getPackageName();  
  13. String price = response.getApp(0).getPrice();  
  14. String rating = response.getApp(0).getRating();  
  15. int ratingCount = response.getApp(0).getRatingsCount();  
  16. String title = response.getApp(0).getTitle();  
  17. String version = response.getApp(0).getVersion();  
  18. int versionCode = response.getApp(0).getVersionCode();  
  19. int serializedSize = response.getApp(0).getSerializedSize();  
  20. ExtendedInfo extendedInfo = response.getApp(0).getExtendedInfo();  
  21. text.setText("id:" + id + "\nCreatorId:" + creatorID  
  22. "\nCreator:" + creator + "\nPackageName:"+ packageName + "\nPrice:" + price + "\nrating:"+ rating + "\nRatingCount:" + ratingCount + "\ntitle:" 
  23. + title + "\nVersion:" + version + "\nversionCode:" 
  24. + versionCode + "\nDownloadsCount:" 
  25. + extendedInfo.getDownloadsCount()  
  26. "\nDownloadsCountText:"+extendedInfo.getDownloadsCountText()+ "\nInstallSize:" + extendedInfo.getInstallSize()  
  27. "\nSerializedSize:" + serializedSize+ "\nDecription:" + extendedInfo.getDescription()+ "\nContactEmail:" + extendedInfo.getContactEmail()+ "\nContactPhone:" + extendedInfo.getContactPhone()+ "\nContactWebsite:" 
  28. + extendedInfo.getContactWebsite());  
  29.             }  
  30.         });  
  31. session.flush();//发送并刷新 

 这是Timers4Me的运行结果:

Programming access to Android Market_android

HowToGetAppComments:

  1. CommentsRequest commentsRequest = CommentsRequest.newBuilder().setAppId("7065399193137006744").setStartIndex(0).setEntriesCount(10).build();session.append(commentsRequest, new Callback<CommentsResponse>() {    
  2. @Override public void onResult(ResponseContext context, CommentsResponse response) {        
  3. System.out.println("Response : " + response);  
  4. // response.getComments(0).getAuthorName()      
  5. // response.getComments(0).getCreationTime()    
  6. // ...   
  7.     } });    
  8. session.flush();   

HowToGetAppScreenshot   :

  1. GetImageRequest imgReq = GetImageRequest.newBuilder().setAppId("-7934792861962808905").setImageUsage(AppImageUsage.SCREENSHOT).setImageId("1").build();       
  2. session.append(imgReq, new Callback<GetImageResponse>() {   
  3. @Override public void onResult(ResponseContext context, GetImageResponse response) {      
  4. try {                        
  5. FileOutputStream fos = new FileOutputStream("icon.png");      
  6. fos.write(response.getImageData().toByteArray());      
  7. fos.close();                           
  8. catch(Exception ex) {      
  9. ex.printStackTrace();     
  10. }}});   
  11. session.flush();  

以上只是抛砖引玉,更多精彩,只有动手才能看到,good luck!