Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Calling java method from tier 2

Author
Message
lumni
9
Years of Service
User Offline
Joined: 28th Mar 2015
Location:
Posted: 28th Mar 2015 23:46 Edited at: 29th Mar 2015 17:04
I'm trying to call a java vibrate method I implemented following this guy's example:

http://forum.thegamecreators.com/?m=forum_view&t=211081&b=41

but I cant find the project he refers to and Im having trouble dealing with the jni related code (to call the java method). Any help is appreciated.

the java code is as follows:

lumni
9
Years of Service
User Offline
Joined: 28th Mar 2015
Location:
Posted: 30th Mar 2015 04:34
I got this to work. Its pretty ugly, and probably inefficient. I didnt completely understand how the JNI works, but its not crashing and doesnt impact performance. Use at your own risk. (Adapted from east's code)

first, I extend NativeActivity:



then, in the AndroidManifest I change the line that sets the main activity to call this one instead. Also, I add vibration permission.



vibrate.cpp file:



vibrate.hpp:

#ifndef VIBRATE_HPP
#define VIBRATE_HPP

bool java_hasVibrator();
void java_vibrate(long ms);

#endif

jni_utill.cpp:



and jni_util.hpp:



in the end, I add the cpp files to Android.mk in the jni folder.

I tried a lot to improve this by only attaching the thread once and re-using it but apparently this causes a crash. The java code could be easily improved but im too tired and pissed for this.
Needless to say, these will only compile with the android template.
If anyone could make this work without re-attaching the thread at each call, please share.

Login to post a reply

Server time is: 2024-04-18 11:19:58
Your offset time is: 2024-04-18 11:19:58