免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3483 | 回复: 1
打印 上一主题 下一主题

Programming access to Android Market [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-27 20:08 |只看该作者 |倒序浏览
如果你在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!
本文出自 “超越梦想” 博客,请务必保留此出处http://breezy.blog.51cto.com/2400264/431834

论坛徽章:
0
2 [报告]
发表于 2011-02-22 11:19 |只看该作者
还不错啊呵呵bolt引擎
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP