如果你在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:
- A google account is required.
- Include androidmarketapi-X.Y.jar and protobuf-java-X.Y.Z.jar in your classpath ,下载地址:http://code.google.com/p/android-market-api/downloads/list
需要把这两个JAR导入项目中,由于很好理解,代码就不加注释了 :-)
HowToSearchApps :
You can search by package using :
- String query = "pname:<package>";
By developper name :
- String query = "pub:<name>";
- String query = "pname:com.luckyxmobile.timers4me";// 通过包名查找程序
- MarketSession session = new MarketSession();
- session.login("your gmail account", "your password");
- AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(0).setEntriesCount(10).setWithExtendedInfo(true).build();
- session.append(appsRequest, new MarketSession.Callback<AppsResponse>() {
- @Override
- public void onResult(ResponseContext context, AppsResponse response) {
- TextView text = (TextView) findViewById(R.id.text);
- String id = response.getApp(0).getId();
- String creatorID = response.getApp(0).getCreatorId();
- String creator = response.getApp(0).getCreator();
- String packageName = response.getApp(0).getPackageName();
- String price = response.getApp(0).getPrice();
- String rating = response.getApp(0).getRating();
- int ratingCount = response.getApp(0).getRatingsCount();
- String title = response.getApp(0).getTitle();
- String version = response.getApp(0).getVersion();
- int versionCode = response.getApp(0).getVersionCode();
- int serializedSize = response.getApp(0).getSerializedSize();
- ExtendedInfo extendedInfo = response.getApp(0).getExtendedInfo();
- text.setText("id:" + id + "\nCreatorId:" + creatorID
- + "\nCreator:" + creator + "\nPackageName:"+ packageName + "\nPrice:" + price + "\nrating:"+ rating + "\nRatingCount:" + ratingCount + "\ntitle:"
- + title + "\nVersion:" + version + "\nversionCode:"
- + versionCode + "\nDownloadsCount:"
- + extendedInfo.getDownloadsCount()
- + "\nDownloadsCountText:"+extendedInfo.getDownloadsCountText()+ "\nInstallSize:" + extendedInfo.getInstallSize()
- + "\nSerializedSize:" + serializedSize+ "\nDecription:" + extendedInfo.getDescription()+ "\nContactEmail:" + extendedInfo.getContactEmail()+ "\nContactPhone:" + extendedInfo.getContactPhone()+ "\nContactWebsite:"
- + extendedInfo.getContactWebsite());
- }
- });
- session.flush();//发送并刷新
这是Timers4Me的运行结果:
HowToGetAppComments:
- CommentsRequest commentsRequest = CommentsRequest.newBuilder().setAppId("7065399193137006744").setStartIndex(0).setEntriesCount(10).build();session.append(commentsRequest, new Callback<CommentsResponse>() {
- @Override public void onResult(ResponseContext context, CommentsResponse response) {
- System.out.println("Response : " + response);
- // response.getComments(0).getAuthorName()
- // response.getComments(0).getCreationTime()
- // ...
- } });
- session.flush();
HowToGetAppScreenshot :
- GetImageRequest imgReq = GetImageRequest.newBuilder().setAppId("-7934792861962808905").setImageUsage(AppImageUsage.SCREENSHOT).setImageId("1").build();
- session.append(imgReq, new Callback<GetImageResponse>() {
- @Override public void onResult(ResponseContext context, GetImageResponse response) {
- try {
- FileOutputStream fos = new FileOutputStream("icon.png");
- fos.write(response.getImageData().toByteArray());
- fos.close();
- } catch(Exception ex) {
- ex.printStackTrace();
- }}});
- session.flush();
以上只是抛砖引玉,更多精彩,只有动手才能看到,good luck!