To get a user id you can use Google Play Licensing Library.
To download this library open SDK Manager => SDK Tools. The path to downloaded library files is:
path_to_android_sdk_on_your_pc/extras/google/market_licensing/library
Include the library in your project (you can simply copy its files).
Next you need some implementation of Policy
interface (you can simply use one of two files from the library: ServerManagedPolicy
or StrictPolicy
).
User id will be provided for you inside processServerResponse()
function:
public void processServerResponse(int response, ResponseData rawData) {
if(rawData != null) {
String userId = rawData.userId
// use/save the value
}
// ...
}
Next you need to construct the LicenseChecker
with a policy and call checkAccess()
function. Use MainActivity.java
as an example of how to do it. MainActivity.java
is located inside this folder:
path_to_android_sdk_on_your_pc/extras/google/market_licensing/sample/src/com/example/android/market/licensing
Don't forget to add CHECK_LICENSE permission to your AndroidManifest.xml.
More about Licensing Library: https://developer.android.com/google/play/licensing