如何使用非官方的Andr​​oid Market的API?如何使用、Andr、oid、Market

2023-09-08 08:31:42 作者:人生

我是从尝试样品code 此处 。但是,我的应用程序崩溃。

我添加记录,并发现它的崩溃在 session.flush(); 所以我删除该行,它不会崩溃了。

不过,这并不达到 onResult 回调。

 包com.mytest.app;

进口com.gc.android.market.api.MarketSession;
进口com.gc.android.market.api.MarketSession.Callback;
进口com.gc.android.market.api.model.Market.AppsRequest;
进口com.gc.android.market.api.model.Market.AppsResponse;
进口com.gc.android.market.api.model.Market.ResponseContext;

进口android.app.Activity;
进口android.os.Bundle;
进口android.provider.Settings.Secure;
进口android.util.Log;

公共类MarketAPITestActivity延伸活动{
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        Log.d(市场API,入门);

        字符串email =somebody@gmail.com;
        字符串传递=为mypass;
        串AndroidId = Secure.getString(this.getContentResolver(),Secure.ANDROID_ID);

        MarketSession会议=新MarketSession();
        session.login(电子邮件,通过);
        。session.getContext()setAndroidId(AndroidId);

        查询字符串=地图;
        AppsRequest appsRequest = AppsRequest.newBuilder()
                                        .setQuery(查询)
                                        .setStartIndex(0).setEntriesCount(10)
                                        .setWithExtendedInfo(真)
                                        。建立();

        session.append(appsRequest,新的回调< AppsResponse>(){
                 @覆盖
                 公共无效onResult(ResponseContext背景下,AppsResponse响应){
                        Log.d(市场API,得到回应);
                 }
        });

        session.flush();
    }
}
 

解决方案

有一个与 androidId 的一个问题。相反的:

 字符串AndroidId = Secure.getString(this.getContentResolver(),Secure.ANDROID_ID);
 

使用这样的:

 字符串AndroidId =dead000beef;
 

它的作品。

I'm trying the sample code from here. But my app is crashing.

I added logging and found out that it's crashing at session.flush(); so I removed that line and it doesn't crash anymore.

But it doesn't reach the onResult callback.

package com.mytest.app;

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.AppsResponse;
import com.gc.android.market.api.model.Market.ResponseContext;

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.util.Log;

public class MarketAPITestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.d("Market API", "Started");

        String email = "somebody@gmail.com";
        String pass = "mypass";
        String AndroidId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);

        MarketSession session = new MarketSession();
        session.login(email,pass);
        session.getContext().setAndroidId(AndroidId);

        String query = "maps";
        AppsRequest appsRequest = AppsRequest.newBuilder()
                                        .setQuery(query)
                                        .setStartIndex(0).setEntriesCount(10)
                                        .setWithExtendedInfo(true)
                                        .build();

        session.append(appsRequest, new Callback<AppsResponse>() {
                 @Override
                 public void onResult(ResponseContext context, AppsResponse response) {
                        Log.d("Market API", "Got response");
                 }
        });

        session.flush();                        
    }
}

解决方案

There is a problem with androidId. Instead of:

String AndroidId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);

Use this:

String AndroidId = "dead000beef";

It Works.