NativeActivity and in-app-billing.

1,693 views
Skip to first unread message

Bram Stolk

unread,
Oct 29, 2012, 4:56:01 PM10/29/12
to andro...@googlegroups.com
Hi,


I've based my app on the NativeActivity sample, which is 100% C, no Java.
Is there a way to add in-app-billing support to a NativeActivity based app?
If so, where do I start?

Thanks,

  Bram

Onur Cinar

unread,
Nov 1, 2012, 1:43:19 AM11/1/12
to andro...@googlegroups.com
Hi Bram,

The native activity is nothing more than the Java based android.app.NativeActivity class delivering the lifecycle events to your C/C++ application. Regarding from that perspective, you are still running within the Java VM, and the entire Java based Android API is available to your native C/C++ code. You can always use the JNIEnv interface in the ANativeActivity structure to access the Java based API.

As there is no native API to use the in-app billing, you should implement the necessary billing service as explained here:

http://developer.android.com/guide/google/play/billing/billing_integrate.html

And then you can then use the JNIEnv interface to access the Java layer from your C/C++ code to invoke the sendBillingRequest() in order to start the in-app billing support.

I hope it helps.

Best regards,

-onur

Bram Stolk

unread,
Nov 1, 2012, 3:03:30 PM11/1/12
to andro...@googlegroups.com
Thank you Onur,

I found this excellent presentation by Bishop from nVidia:

He presented some options, and one of them was to derive a new class from NativeActivity.

So that's what I went with, and added Java code to my project.
And I call that java from C.
In his example, he wraps the actual java work with runOnUiThread()
Which seems a safe thing to do.

  bram

Onur Cinar

unread,
Nov 1, 2012, 4:47:59 PM11/1/12
to android-ndk
Hi Bram,

Excellent, thanks for sharing the presentation too. I'm glad that it
worked out.

Best regards,

-onur


On Nov 1, 12:03 pm, Bram Stolk <b.st...@gmail.com> wrote:
> Thank you Onur,
>
> I found this excellent presentation by Bishop from nVidia:http://developer.download.nvidia.com/assets/gamedev/files/gdc12/Andro...
>
> He presented some options, and one of them was to derive a new class from
> NativeActivity.
>
> So that's what I went with, and added Java code to my project.
> And I call that java from C.
> In his example, he wraps the actual java work with runOnUiThread()
> Which seems a safe thing to do.
>
>   bram
>
>
>
>
>
>
>
> On Wednesday, October 31, 2012 10:43:20 PM UTC-7, Onur Cinar wrote:
>
> > Hi Bram,
>
> > The native activity is nothing more than the Java based
> > android.app.NativeActivity class delivering the lifecycle events to your
> > C/C++ application. Regarding from that perspective, you are still running
> > within the Java VM, and the entire Java based Android API is available to
> > your native C/C++ code. You can always use the JNIEnv interface in the
> > ANativeActivity structure to access the Java based API.
>
> > As there is no native API to use the in-app billing, you should implement
> > the necessary billing service as explained here:
>
> >http://developer.android.com/guide/google/play/billing/billing_integr...
Reply all
Reply to author
Forward
0 new messages