【问题标题】:How do I use the unofficial Android Market API?如何使用非官方的 Android Market API?
【发布时间】:2011-08-04 15:44:45
【问题描述】:

我正在尝试来自here 的示例代码。但是我的应用程序崩溃了。

我添加了日志记录,发现它在 session.flush(); 处崩溃,所以我删除了该行,它不再崩溃了。

但它没有到达onResult 回调。

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();                        
    }
}

【问题讨论】:

  • 你能发布你的代码吗?还有例外吗?
  • 用代码更新了问题。我试图用 try/catch 捕捉异常,但 eclipse 说它无法到达,所以我不得不删除它。我不确定在哪里添加 try/catch。
  • 你能发布异常吗?如果你查看你的 logcat,它应该在 session.flush(); 处显示一个异常;
  • 好的,问题与android id有关。当我将 android id 更改为“dead000beef”时,我得到了来自服务器的有效响应。当我使用自己的 androidid 时,出现 400 错误。
  • session.login 总是抛出 LoginException 错误。有什么帮助吗?

标签: java android flush google-play


【解决方案1】:

androidId 有问题。而不是:

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

使用这个:

String AndroidId = "dead000beef";

它有效。

【讨论】:

    【解决方案2】:

    我强烈建议您查看https://groups.google.com/forum/#!forum/android-market-api(我所知道的唯一一个仍在使用 Android Market API 的地方)。

    请注意,身份验证方法(登录名/密码)现在已被弃用(而且不安全),并且可能不再受当前市场协议的支持。

    此外,有效的 android id 不再像以前那样简单地检索,也请参阅组。

    【讨论】:

      【解决方案3】:

      这不是 Secure.ANDROID_ID,它是 Gtalk 服务设备 ID。

      您可以使用以下代码:

      public String getDeviceId(Context context) {
          String[] params = { GSERVICES_ID_KEY };
          Cursor c = context.getContentResolver()
                  .query(GSERVICES_URI, null, null, params, null);
      
          if (!c.moveToFirst() || c.getColumnCount() < 2)
              return null;
      
          try {
              return Long.toHexString(Long.parseLong(c.getString(1))).toUpperCase();
          } catch (NumberFormatException e) {
              return null;
          }
      }
      

      并添加读取Gservice的权限

      <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
      

      【讨论】:

      • GSERVICES_ID_KEY 和 GSERVICES_URI 的值是多少
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多