Programming access to Android Market

发布于 2022-09-14 17:12:29 字数 6209 浏览 35 评论 1

如果你在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的运行结果:

232351880.png (35.57 KB, 下载次数: 6)

下载附件

2011-01-27 20:07 上传



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!
本文出自 “超越梦想” 博客,请务必保留此出处http://breezy.blog.51cto.com/2400264/431834

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小猫一只 2022-09-14 21:22:41

还不错啊呵呵bolt引擎

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文