一个程序从Google应用市场获取程序信息的Demo

import java.io.FileOutputStream ;
 
import com.gc.android.market.api.MarketSession ;
import com.gc.android.market.api.MarketSession.Callback ;
import com.gc.android.market.api.model.Market.AppsRequest ;
import com.gc.android.market.api.model.Market.CommentsRequest ;
import com.gc.android.market.api.model.Market.GetImageRequest ;
import com.gc.android.market.api.model.Market.GetImageResponse ;
import com.gc.android.market.api.model.Market.ResponseContext ;
import com.gc.android.market.api.model.Market.GetImageRequest.AppImageUsage ;
 
public class Main {
public static void main ( String [] args ) {
try {
if ( args . length < 2 ) {
System . out . println ( "Usage :\n" +
"market email password query" );
return ;
}
 
 
String login = args [ 0 ];
String password = args [ 1 ];
String query = args . length > 2 ? args [ 2 ] : "Test" ;
 
MarketSession session = new MarketSession ();
session . getContext (). setAndroidId ( "0123012301230123" );
session . getContext (). setDeviceAndSdkVersion ( "passion:8" );
session . getContext (). setVersion ( 1002012 );
 
System . out . println ( "Login..." );
session . login ( login , password );
System . out . println ( "Login done" );
 
AppsRequest appsRequest = AppsRequest . newBuilder ()
. setQuery ( query )
. setStartIndex ( 2 ). setEntriesCount ( 10 )
. setWithExtendedInfo ( true )
. build ();
 
CommentsRequest commentsRequest = CommentsRequest . newBuilder ()
. setAppId ( "7065399193137006744" )
. setStartIndex ( 0 )
. setEntriesCount ( 10 )
. build ();
 
GetImageRequest imgReq = GetImageRequest . newBuilder (). setAppId ( "-7934792861962808905" )
. setImageUsage ( AppImageUsage . SCREENSHOT )
. setImageId ( "1" )
. build ();
 
MarketSession . Callback callback = new MarketSession . Callback () {
@Override
public void onResult ( ResponseContext context , Object response ) {
System . out . println ( "Response : " + response );
}
 
};
session . append ( appsRequest , callback );
session . flush ();
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 ();
session . append ( commentsRequest , callback );
session . flush ();
} catch ( Exception ex ) {
ex . printStackTrace ();
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值