如何使用非官方 Android Market API?

发布于 2024-11-28 02:06:47 字数 2137 浏览 1 评论 0原文

我正在尝试此处中的示例代码。但我的应用程序崩溃了。

我添加了日志记录,发现它在 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 = "[email protected]";
        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();                        
    }
}

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 = "[email protected]";
        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();                        
    }
}

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

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

发布评论

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

评论(3

朮生 2024-12-05 02:06:47

androidId 有问题。而不是:

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

使用这个:

String AndroidId = "dead000beef";

它有效。

There is a problem with androidId. Instead of:

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

Use this:

String AndroidId = "dead000beef";

It Works.

遥远的她 2024-12-05 02:06:47

我强烈建议您查看 https://groups.google.com /forum/#!forum/android-market-api(据我所知,这是唯一一个仍然活跃于 Android Market API 的地方)。

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

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

I strongly suggest to take a look at https://groups.google.com/forum/#!forum/android-market-api (the only place I know still being active about Android Market API).

Please take in account that the authentication method (login/pwd) is more than deprecated now (and not secure), and might not be anymore supported by the current market protocol.

Also a valid android id is not anymore as simple as before to retreive, see the groups for that too.

我偏爱纯白色 2024-12-05 02:06:47

这不是 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"/>

This is not Secure.ANDROID_ID, it's Gtalk service device ID.

You can use the following code:

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

And add the permission to read Gservice

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文