[工作积累] Google Play Services

时间:2023-03-10 03:02:20
[工作积累] Google Play Services

注意添加APP_ID

       <meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>

使用对应的AndroidInitialization方法

gpg-cpp-sdk/android/include/gpg/android_initialization.h

 /**
* @file gpg/android_initialization.h
*
* @brief Android specific initialization functions.
*/ #ifndef GPG_ANDROID_INITIALIZATION_H_
#define GPG_ANDROID_INITIALIZATION_H_ #ifndef __cplusplus
#error Header file supports C++ only
#endif // __cplusplus #include <android/native_activity.h>
#include <jni.h>
#include "gpg/common.h" // Forward declaration of android_app from android_native_app_glue.h.
struct android_app; namespace gpg { /**
* AndroidInitialization includes three initialization functions, exactly one of
* which must be called. In the case of a standard Java Activity, JNI_OnLoad
* should be used. In the case of a NativeActivity where JNI_OnLoad will not be
* called, either android_main or ANativeActivity_onCreate should be used.
* android_main is used when building a NativeActivity using
* android_native_app_glue.h. ANativeActivity_onCreate is used when building a
* NativeActivity using just native_activity.h. android_native_app_glue.h and
* native_activity.h are default Android headers.
*
* The appropriate initialization function must be called exactly once before
* any AndroidPlatformConfiguration instance methods are called, and it must be
* called before a GameServices object is instantiated. It is permitted to
* instantiate a AndroidPlatformConfiguration before one of the intialization
* calls (for example, if the configuration object has global scope), as long as
* no methods are called before the initialization call. These methods need be
* called only once in the lifetime of the calling program, not once per
* GameServices object created.
*/
struct GPG_EXPORT AndroidInitialization {
/**
* When using Play Game Services with a standard Java Activity, JNI_OnLoad
* should be called when the dynamic library's JNI_OnLoad is called.
*/
static void JNI_OnLoad(JavaVM *jvm); /**
* When using Play Game Services with a NativeActivity which is based on
* android_native_app_glue.h, android_main should be called during your
* activity's android_main, before any other Play Game Services calls.
*/
static void android_main(struct android_app *app); /**
* When using Play Game Services with a NativeActivity which is based on only
* native_activity.h, ANativeActivity_onCreate should be called during your
* activity's ANativeActivity_onCreate, before any other Play Game Services
* calls.
*/
static void ANativeActivity_onCreate(ANativeActivity *native_activity,
void *savedState,
size_t savedStateSize);
}; } // namespace gpg #endif // GPG_ANDROID_INITIALIZATION_H_

API Level 14以上: OnActivityResult必须调用, 其他不需要.  14以下都需要.

gpg-cpp-sdk/android/include/gpg/android_support.h

 #ifndef __cplusplus
#error Header file supports C++ only
#endif // __cplusplus #include "gpg/common.h" namespace gpg { /**
* Functions which enable pre- Android 4.0 support.
*
* <h1>Android Lifecycle Callbacks</h1>
*
* For apps which target Android 2.3 or 3.x devices (API Version prior to 14),
* Play Game Services has no way to automatically receive Activity lifecycle
* callbacks. In these cases, Play Game Services relies on the owning Activity
* to notify it of lifecycle events. Any Activity which owns a GameServices
* object should call the AndroidSupport::* functions from within their own
* lifecycle callback functions. The arguments in these functions match those
* provided by Android, so no additional processing is necessary.
*
* For apps which target android 4.0+ (API Version greater than or equal to 14),
* most of these function calls are unnecessary. For such apps only the
* OnActivityResult function must be called.
...

Update: IAP/Google IAB

ref: http://developer.android.com/google/play/billing/billing_testing.html

遇到的问题:

response code 4: item unavailable

"the item you requested is not available for purchase"

http://developer.android.com/google/play/billing/v2/billing_reference.html

RESULT_ITEM_UNAVAILABLE    4

Indicates that Google Play cannot find the requested item in the application's product list. This can happen if the product ID is misspelled in your REQUEST_PURCHASE request or if an item is unpublished in the application's product list.

Check list: (answered by nmw01223)

http://*.com/questions/11020587/in-app-billing-item-requested-not-available-for-purchase

对照检查, 我这里的问题是第6条:

dev console上上传的的APK, versionCode为6, 设备测试用的APK, versionCode 12.

将本地设备使用的版本号改为6, 问题解决. 估计将新版本的APK上传到dev console也可以解决这个问题.