Tuesday, October 2, 2012

Android Vibration Support in Unity3D

Hi everyone,

today I want to talk about Android Vibration in Unity3D.

As I tested on Kindle, the SystemInfo.supportsVibration returned true even if there's no vibrator on it.
So, I decided to Call the native Android Java Class. 
That was my code :
_____________________________________________________________________
AndroidJavaObject activity;
AndroidJavaObject mWindowManager;
bool result;
   
public void Start()
{  
        if (mWindowManager == null)
        {
                using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").
                            GetStatic<AndroidJavaObject>("currentActivity"))
         {
                mWindowManager = activity.Call<AndroidJavaObject>("getSystemService","sensor");
          }
}
result = mWindowManager.Call<bool>("hasVibrator");

________________________________________________________________________

But all my tries were useless. In fact,  as I saw on this link, the function I wanted to call, which is hasVibrator(), can only be used on API 11 ( Android 3.0 ) .

So in all Android Systems from 2.0 to 2.3.3 vibration support can't be checked !!!!!!!


So, if I'll find some different way to check that, it will be written on this blog :)

Cheers,
Nik


No comments:

Post a Comment