游戏人生

不积跬步,无以至千里;不积小流,无以成江海。

导航

[工作积累] Google Play Services

注意添加APP_ID

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

 

使用对应的AndroidInitialization方法

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

 1 /**
 2  * @file gpg/android_initialization.h
 3  *
 4  * @brief Android specific initialization functions.
 5  */
 6 
 7 #ifndef GPG_ANDROID_INITIALIZATION_H_
 8 #define GPG_ANDROID_INITIALIZATION_H_
 9 
10 #ifndef __cplusplus
11 #error Header file supports C++ only
12 #endif  // __cplusplus
13 
14 #include <android/native_activity.h>
15 #include <jni.h>
16 #include "gpg/common.h"
17 
18 // Forward declaration of android_app from android_native_app_glue.h.
19 struct android_app;
20 
21 namespace gpg {
22 
23 /**
24  * AndroidInitialization includes three initialization functions, exactly one of
25  * which must be called. In the case of a standard Java Activity, JNI_OnLoad
26  * should be used. In the case of a NativeActivity where JNI_OnLoad will not be
27  * called, either android_main or ANativeActivity_onCreate should be used.
28  * android_main is used when building a NativeActivity using
29  * android_native_app_glue.h. ANativeActivity_onCreate is used when building a
30  * NativeActivity using just native_activity.h. android_native_app_glue.h and
31  * native_activity.h are default Android headers.
32  *
33  * The appropriate initialization function must be called exactly once before
34  * any AndroidPlatformConfiguration instance methods are called, and it must be
35  * called before a GameServices object is instantiated. It is permitted to
36  * instantiate a AndroidPlatformConfiguration before one of the intialization
37  * calls (for example, if the configuration object has global scope), as long as
38  * no methods are called before the initialization call. These methods need be
39  * called only once in the lifetime of the calling program, not once per
40  * GameServices object created.
41  */
42 struct GPG_EXPORT AndroidInitialization {
43   /**
44    * When using Play Game Services with a standard Java Activity, JNI_OnLoad
45    * should be called when the dynamic library's JNI_OnLoad is called.
46    */
47   static void JNI_OnLoad(JavaVM *jvm);
48 
49   /**
50    * When using Play Game Services with a NativeActivity which is based on
51    * android_native_app_glue.h, android_main should be called during your
52    * activity's android_main, before any other Play Game Services calls.
53    */
54   static void android_main(struct android_app *app);
55 
56   /**
57    * When using Play Game Services with a NativeActivity which is based on only
58    * native_activity.h, ANativeActivity_onCreate should be called during your
59    * activity's ANativeActivity_onCreate, before any other Play Game Services
60    * calls.
61    */
62   static void ANativeActivity_onCreate(ANativeActivity *native_activity,
63                                        void *savedState,
64                                        size_t savedStateSize);
65 };
66 
67 }  // namespace gpg
68 
69 #endif  // GPG_ANDROID_INITIALIZATION_H_

 

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

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

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

 

 


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://stackoverflow.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也可以解决这个问题.

 

posted on 2015-09-02 17:49  crazii  阅读(855)  评论(0编辑  收藏  举报