Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Android] show AdView from Android Java Code on SFML  (Read 2083 times)

0 Members and 1 Guest are viewing this topic.

darrit

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
[Android] show AdView from Android Java Code on SFML
« on: August 14, 2015, 09:30:50 pm »
Hey guys,

I have a question about AdView (Advertising View from Android Java Code) and  SFML.


Is there any way to show a AdView on the screen using SFML ?
I search so much about this but I found nothing useful staff.

I am using the SFML c++ source.


I hope anyone knows a great solution :)
« Last Edit: August 14, 2015, 09:34:22 pm by darrit »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] show AdView from Android Java Code on SFML
« Reply #1 on: August 14, 2015, 11:21:29 pm »
Sadly I lost the source of my App (Kroniax) but i implemented it. I used this tutorial: http://www.dynadream.com/ddweb/index.php/Special_Blog?id=20

You will have to call this function with JNI (google it how to call a Java Function from C++, you have no parameters so it's like 5lines of code Edit they added the c++ call, so no need to google it). But you need the NativeActivity and SFML still doesn't provide access to it  ::). But if you want i can send you a hack how to get it without modifying the SFML source.

I changed it a bit to have 2 Java functions showAds() and hideAds(). I think the code to hide the adview is somewhere in the comments



AlexAUT

darrit

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: [Android] show AdView from Android Java Code on SFML
« Reply #2 on: August 14, 2015, 11:33:45 pm »
Hi Alex thanks for your answer :).

Can you tell me what you use for your app ? Only SFML and the Java Android staff ?

It would be great if you can send it to me.
I´ve found this website too but it doesnt work :/ and the tutorial for NDK or SFML for AdView etc. are toooooo much to read and test it all ....  >:(

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] show AdView from Android Java Code on SFML
« Reply #3 on: August 15, 2015, 12:06:13 am »
Yeah I used only SFML with a Custom Activity to implement the functions (add/hideAds in java). You have to change a few things in the manifest, sadly I do not remember what excatly (the default start activity, change it from nativeactivity to your custom activity)

The hack to get access to the NativeActivity is easy but ugly :P 3 simple steps:

1) Copy these files from the SFML src directory to your project: Activity.hpp EGLCheck.hpp EGLContext.hpp GlContext.hpp. Because you will have to include Activity.hpp (which includes the other ones, you will have to change the #include inside these files).

2) You need to get the SFML states (include Activity.hpp) to retrieve the NativeActivity: see here: https://github.com/AlexAUT/AwEngine/blob/master/include/aw/utility/systemValues.cpp#L30

3) Use the exposed NativeActivity, for JNI (get the JavaEnviroment, or get the InternalPath in my like a few lines above).

(Keep in mind you should lock the sates when you use it, to prevent race conditions with the event thread of SFML)


And from there on you can just follow the tutorial on the site linked above


AlexAUT

darrit

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: [Android] show AdView from Android Java Code on SFML
« Reply #4 on: August 15, 2015, 01:09:23 am »
Ok I´ll try it thank you :)
If i have more question about this I text you ok ? ^^

Thank you again so much  :) and have a nice evening.
Schönen Abend noch  ;D.

darrit

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] show AdView from Android Java Code on SFML
« Reply #5 on: August 15, 2015, 07:55:34 am »
Sure you can always PM me. But if it is a question other people will have in the future too consider creating a new thread so they can find the answer and not have to ask them too.


AlexAUT