如何使用非官方 Android Market API?
我正在尝试此处
中的示例代码。但我的应用程序崩溃了。
我添加了日志记录,发现它在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
androidId
有问题。而不是:使用这个:
它有效。
There is a problem with
androidId
. Instead of:Use this:
It Works.
我强烈建议您查看 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.
这不是 Secure.ANDROID_ID,而是 Gtalk 服务设备 ID。
可以使用如下代码:
并添加读取Gservice的权限
This is not Secure.ANDROID_ID, it's Gtalk service device ID.
You can use the following code:
And add the permission to read Gservice