暫時記一下,有空再來整理

 

While googling around, I've stumbled upon an interesting project - Android Market API. This project is clearly a result of some Android reverse engineering work, still it's hosted on Google Code site. Funny, isn't it? Oh, by the way - the Android Market protocol uses Google's Protocol Buffers with HTTP as a transport layer.

Anyway, to play with the API you need a Google account (obviously), but also a sort of device identifier referred to as "Android ID". Funny enough, this is not the Android ID which can be obtained usingandroid.provider.Settings.Secure class etc., the right ID can be obtained by "dialing" *#*#8255#*#* - look forDevice ID, remove `android-` prefix.

But is there a way to retrieve this ID programmatically? It required a bit of hacking to reveal, but here's the recipe:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private static final Uri URI = Uri
private static final String ID_KEY = "android_id";
 
String getAndroidId(Context ctx) {
    String[] params = { ID_KEY };
    Cursor c = ctx.getContentResolver()
            .query(URI, null, null, params, null);
 
    if (!c.moveToFirst() || c.getColumnCount() < 2)
        return null;
 
    try {
        return Long.toHexString(Long.parseLong(c.getString(1)));
    } catch (NumberFormatException e) {
        return null;
    }
}

This code requires extra com.google.android.providers.gsf.permission.READ_GSERVICES permission, be sure to add the following line to your AndroidManifest.xml:

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

That's it!

 

轉自http://blog.codepainters.com/2012/01/17/how-to-obtain-gtalk-android-id/

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 toyangel 的頭像
    toyangel

    好同學的部落格

    toyangel 發表在 痞客邦 留言(0) 人氣()