예제 #1
0
/// ---------------------------------------------------------------------------
/// 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();
            }
        }
    }
}
예제 #2
0
/// ---------------------------------------------------------------------------
/// 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();
        }
    }
}
예제 #3
0
/// ---------------------------------------------------------------------------
/// 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();
        }
    }
}
예제 #4
0
/// ---------------------------------------------------------------------------
/// 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();
        }
    }
}