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

Author Topic: [Android] How to vibrate the device?  (Read 4166 times)

0 Members and 1 Guest are viewing this topic.

CytraL

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • GitHub
[Android] How to vibrate the device?
« on: August 15, 2014, 09:05:53 pm »
Hi again...

How to vibrate the device or get the native activity?

thx!
dev@redneboa.es | WordPress | GitHub | YouTube

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: [Android] How to vibrate the device?
« Reply #1 on: August 16, 2014, 06:17:35 am »
You can't with the SFML port as far as I understand.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

paupav

  • Full Member
  • ***
  • Posts: 156
    • View Profile
    • Email
Re: [Android] How to vibrate the device?
« Reply #2 on: August 16, 2014, 01:39:37 pm »
I also haven't found anything googling it. Well, at least you can always call yourself during gaming.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] How to vibrate the device?
« Reply #3 on: August 16, 2014, 01:47:29 pm »
If you need this feature immediately you could write a JNI wrapper around this API (Do not forget to add the permission for vibration): http://developer.android.com/reference/android/os/Vibrator.html
I don't think there is a native library for it.

AlexAUT

CytraL

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • GitHub
Re: [Android] How to vibrate the device?
« Reply #4 on: August 16, 2014, 04:33:23 pm »
You can't with the SFML port as far as I understand.
:(

I also haven't found anything googling it. Well, at least you can always call yourself during gaming.
yes! the best solution with difference xDDD

If you need this feature immediately you could write a JNI wrapper around this API (Do not forget to add the permission for vibration): http://developer.android.com/reference/android/os/Vibrator.html
I don't think there is a native library for it.

AlexAUT
Thx! i read about it but i need get the NativeActivity for get the 'JNIEnv' no?

---------

Thx all for reply
dev@redneboa.es | WordPress | GitHub | YouTube

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] How to vibrate the device?
« Reply #5 on: August 16, 2014, 10:30:40 pm »
I did a little hack for Kroniax to get access to the "NativeActivity". Just copy the "Activity.hpp" from the sfml/src/system/android directory to your project and include it in a source file. Then you can use sf::priv::getActivity(nullptr)->Activity to get the NativeActivity.
It's just a hack and I don't know if its a good one, but it worked for my game  ;) (There could be race conditions)

I hope SFML will implement a out of box solution for this.


AlexAUT

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [Android] How to vibrate the device?
« Reply #6 on: August 16, 2014, 10:36:55 pm »
Can't you simply rely on `sf::Window::getSystemHandle`?

The impl specific to Android is here: https://github.com/SFML/SFML/blob/master/src/SFML/Window/Android/WindowImplAndroid.cpp#L87
SFML / OS X developer

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] How to vibrate the device?
« Reply #7 on: August 17, 2014, 10:22:56 am »
Can't you simply rely on `sf::Window::getSystemHandle`?

No, because you will get the NativeWindow, but you will need the NativeActivity to set up the Java call...


AlexAUT

CytraL

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • GitHub
Re: [Android] How to vibrate the device?
« Reply #8 on: August 17, 2014, 03:40:18 pm »
Exactly.. getSystemHandle returns ANativeWindow.
dev@redneboa.es | WordPress | GitHub | YouTube

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [Android] How to vibrate the device?
« Reply #9 on: August 17, 2014, 03:47:55 pm »
Okay, I was expecting some function to get the activity from a window... too bad.
SFML / OS X developer

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: [Android] How to vibrate the device?
« Reply #10 on: August 17, 2014, 03:55:52 pm »
I don't think something like that exists. The problem is, a user of the NDK need the NativeActivity to get access to the AssetsManager, which is used to load assets  ::)

So maybe we should think of a good way to expose the NativeActivity, so I can drop my hack.


Edit: Created an issue on github: Link


AlexAUT
« Last Edit: August 17, 2014, 06:02:42 pm by AlexAUT »

 

anything