About Store Forum Documentation Contact
Donations:
289$/mo



Post Reply 
In-app Billing for Android
Author Message
Rollcage Offline
Member

Post: #1
In-app Billing for Android
Does esenthel support in-app purchases for android? Apparently any application that uses a level 4 API or higher has this ability.
08-04-2012 05:08 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: In-app Billing for Android
This functionality is not natively supported by the engine.
08-06-2012 08:17 PM
Find all posts by this user Quote this message in a reply
Rollcage Offline
Member

Post: #3
RE: In-app Billing for Android
Is it possible for me to implement this or does it have to be done on your side?
09-17-2012 12:27 AM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #4
RE: In-app Billing for Android
I think it must be implemented by yourself with Java. Google has a good tutorial:
http://developer.android.com/guide/googl...index.html
I will need add this feature in my game too.

IRC: irc.freenode.net
Channel: #Esenthel
09-17-2012 02:55 AM
Find all posts by this user Quote this message in a reply
Rollcage Offline
Member

Post: #5
RE: In-app Billing for Android
That's what I though, atleast until Esenthel has some spare time. So we implement it in java and rebuild the Esenthel-Android SDK and have a way to call the java services from c++?

I will have a go at this soon and will let you know if there's any progress
09-17-2012 04:34 AM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #6
RE: In-app Billing for Android
No, if you dont have the Ultimate Licence, you cant rebuild Esenthel SDK for Android. Esenthel only provides precompiled libraries. What you need to comunicate c++ (your game sources) and Java, is JNI (Java Native Interface).

http://developer.android.com/guide/practices/jni.html

I've worked in 2 comercial projects for GPlay and Amazon Market with JNI and Android NDK. Tell me if you need example files.

IRC: irc.freenode.net
Channel: #Esenthel
09-17-2012 06:49 AM
Find all posts by this user Quote this message in a reply
Rollcage Offline
Member

Post: #7
RE: In-app Billing for Android
Yea I've just done a bit more reading and stumbled upon that. Any example files / tips would be appreciated. Sounds like you know what is involved to integrate this.
09-17-2012 07:03 AM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #8
RE: In-app Billing for Android
Java side:

NativeLib.java
Code:
package com.company.game;

public class NativeLib
{
        //Java declarations of native functions. Key word here is native.

        public static native int init();
        public static native int somefunction(int x, int y, String cad);
        
        
       // Java functions that will be called from C++
     private static void javanamefunction(String str, double x)
    {
        //Here In-app purchases calls.
    }

}

C++ side (file inside jni folder)

NativeInterface.cpp
Code:
#include <jni.h> //The important header
#include <string>

static JavaVM*  s_vm = 0;

jclass libClass;

jmethodID javanamefunctionMethod;

JavaVM* ME_JavaVM()
{
        return s_vm;
}

extern "C"
{
        // Java => C++ methods. The name must be [Java_] + [PackageName] + [Filename] + [Function name]. And of course parameters must be the same.

        JNIEXPORT jint JNICALL Java_com_company_game_NativeLib_init(JNIEnv* env, jobject obj);
        JNIEXPORT void JNICALL Java_com_company_game_NativeLib_somefunction(JNIEnv * env, jobject obj, int x, int y, jstring cad);

}

JNIEXPORT jint JNICALL Java_com_company_game_NativeLib_init(JNIEnv* env, jobject obj)
{
        // Obtain the Java class.
        env->GetJavaVM(&s_vm);
        libClass = env->FindClass("com/company/game/NativeLib");

        assert(libClass);

        // C++ => Java methods.
        javanamefunctionMethod = env->GetStaticMethodID(libClass, "javanamefunction", "(Ljava/lang/String;D)V");

        assert(javanamefunctionMethod);

        return 0;
}

JNIEXPORT void JNICALL Java_com_company_game_NativeLib_somefunction(JNIEnv * env, jobject obj, int x, int y, jstring cad)
{
      const char *convstr = env->GetStringUTFChars(cad, 0);

     //Operations with convstr;

      env->ReleaseStringUTFChars(cad, convstr);
}

// C++ => Java

void android_paymoney(const char* id, double money)
{
        JavaVM* vm = ME_JavaVM();
        JNIEnv* env = 0;

        int vm_attached = vm->GetEnv((void**)&env, JNI_VERSION_1_6);

        assert(env);

        assert( vm_attached == JNI_OK );

        env->CallStaticVoidMethod(libClass,  javanamefunctionMethod, id, money);
}

First you must call init() (from Java). I do it when creating the GLView, we need investigate where to call this because it should depend of Esenthel intialization.

- How to call c++ functions from Java?

NativeLib.init();
NativeLib.somefunction(5,5,"hi");

- How to call java functions from c++?

extern android_paymoney(const char* id, double money); // Declare this line at the begining of the file for example

android_paymoney("weapon2", 10000);

----------

Of course you need to learn how to pass variables, I did put some examples with strings, ints and doubles.

I hope it helps.

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 09-17-2012 08:37 AM by cmontiel.)
09-17-2012 08:29 AM
Find all posts by this user Quote this message in a reply
Rollcage Offline
Member

Post: #9
RE: In-app Billing for Android
Thanks for that, looks like it will be very helpful. Hopefully I will have some time soon to attempt.
09-17-2012 09:46 AM
Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #10
RE: In-app Billing for Android
Thanks cmontiel for the good example!

I see this is on the roadmap:
In-app Billing and AdMob support for Android and iOS

Any plans on putting this on the contribution page?
How far away is it?
This is really important to indies!
10-13-2013 11:57 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply