/// --------------------------------------------------------------------------- /// Begins a purchase /// --------------------------------------------------------------------------- void prJNI_BeginPurchase(const char *item) { if (item && *item) { JavaVM *pJavaVM = prJNI_GetVM(); PRASSERT(pJavaVM); if (pJavaVM) { bool isAttached = false; JNIEnv *env = NULL; // Get environment. if (!prJNI_GetEnv(&env, isAttached)) return; // Find class jclass cls = prJNI_GetTheClass(env, "InAppPurchase", isAttached); if (!cls) return; // Find the callBack method ID jmethodID method = env->GetStaticMethodID(cls, "beginPurchase", "(Ljava/lang/String;)V"); if (!method) { __android_log_print(ANDROID_LOG_ERROR, "Proteus", "Failed to get method ID %s", "beginPurchase"); if (isAttached) { pJavaVM->DetachCurrentThread(); } return; } // Construct a Java string. jstring js = env->NewStringUTF(item); env->CallStaticVoidMethod(cls, method, js); // And done if (isAttached) { pJavaVM->DetachCurrentThread(); } } } }
/// --------------------------------------------------------------------------- /// Plays a song. /// --------------------------------------------------------------------------- void prJNI_SongPlay(const char *filename) { JavaVM *pJavaVM = prJNI_GetVM(); PRASSERT(pJavaVM); if (pJavaVM) { bool isAttached = false; JNIEnv *env = NULL; // Get environment. if (!prJNI_GetEnv(&env, isAttached)) return; // Find class jclass cls = prJNI_GetAudioClass(env, "Music", isAttached); if (!cls) return; // Find the callBack method ID jmethodID method = env->GetStaticMethodID(cls, "songPlay", "(Ljava/lang/String;)V"); if (!method) { prTrace(LogError, "Failed to get method ID %s", "songPlay"); if (isAttached) { pJavaVM->DetachCurrentThread(); } return; } // Construct a Java string. jstring js = env->NewStringUTF(filename); env->CallStaticVoidMethod(cls, method, js); // And done if (isAttached) { pJavaVM->DetachCurrentThread(); } } }
/// --------------------------------------------------------------------------- /// Opens a facebook session /// --------------------------------------------------------------------------- void prJNI_FacebookOpenSession() { JavaVM *pJavaVM = prJNI_GetVM(); PRASSERT(pJavaVM); if (pJavaVM) { bool isAttached = false; JNIEnv *env = NULL; // Get environment. if (!prJNI_GetEnv(&env, isAttached)) return; // Find class jclass cls = prJNI_GetFacebookClass(env, "Facebook", isAttached); if (!cls) return; // Find the callBack method ID jmethodID method = env->GetStaticMethodID(cls, "openSession", "()V"); if (!method) { __android_log_print(ANDROID_LOG_ERROR, "Proteus", "Failed to get method ID %s", "openSession"); if (isAttached) { pJavaVM->DetachCurrentThread(); } return; } // Call. env->CallStaticVoidMethod(cls, method); // And done if (isAttached) { pJavaVM->DetachCurrentThread(); } } }
/// --------------------------------------------------------------------------- /// Resumes playing the current song. /// --------------------------------------------------------------------------- void prJNI_SongResume() { JavaVM *pJavaVM = prJNI_GetVM(); PRASSERT(pJavaVM); if (pJavaVM) { bool isAttached = false; JNIEnv *env = NULL; // Get environment. if (!prJNI_GetEnv(&env, isAttached)) return; // Find class jclass cls = prJNI_GetAudioClass(env, "Music", isAttached); if (!cls) return; // Find the callBack method ID jmethodID method = env->GetStaticMethodID(cls, "songResume", "()V"); if (!method) { prTrace(LogError, "Failed to get method ID %s", "songResume"); if (isAttached) { pJavaVM->DetachCurrentThread(); } return; } // Call. env->CallStaticVoidMethod(cls, method); // And done if (isAttached) { pJavaVM->DetachCurrentThread(); } } }