Buzz

Discussions specifically related to the Android and iOS editions of BBCSDL
Post Reply
roy
Posts: 31
Joined: Mon 02 Apr 2018, 15:48

Buzz

Post by roy » Fri 06 Apr 2018, 14:35

Hi All

I would like the Android screen to buzz/vibrate when it is tapped. I've looked on line without success.

Any ideas

Thanks Roy

guest
Site Admin
Posts: 103
Joined: Mon 02 Apr 2018, 09:12

Re: Buzz

Post by guest » Fri 06 Apr 2018, 16:30

roy wrote:
Fri 06 Apr 2018, 14:35
I would like the Android screen to buzz/vibrate when it is tapped. I've looked on line without success.
Just to be clear, when you say the "screen" to buzz, I presume you mean that you want to be able to make the device vibrate in the same way as it would when (for example) an incoming telephone call arrives while set to 'silent' (this isn't connected with the screen, as such).

The most important thing to say is that making an Android device vibrate requires an explicit app permission (android.permission.VIBRATE) which BBC BASIC does not request, so this is impossible with a program running under control of the 'IDE'. You could only achieve it by building an app using the BBC2APK tool, and specifying this in the 'Custom manifest' box:

Code: Select all

<manifest><uses-permission android:name="android.permission.VIBRATE"/>
Having done that your program would need to execute the equivalent to this Java code using JNI:

Code: Select all

// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 400 milliseconds
v.vibrate(400);
I am by no means an expert in converting native Java code firstly into JNI code and then into BBC BASIC code (Google suggests that even the first step, making it vibrate from JNI code, is not easy) so this is going to be quite a challenge. Good luck, and if you do make it work be sure to post your code here!

Richard.

roy
Posts: 31
Joined: Mon 02 Apr 2018, 15:48

Re: Buzz

Post by roy » Fri 06 Apr 2018, 17:16

OK Thanks Richard

As you say 'it's going to be quite a challenge' :shock:

Regards Roy

Post Reply