- Home /
Question by
getconnect2ali · Jul 02, 2020 at 04:47 AM ·
androidunity 5iosxcode
Accessing the volume buttons on iPhone for some functionality through Unity
I have created one Unity basic game and take a build for Android and its working well but once I was trying to take build for Xcode then some issues are coming. basically I was trying to take some task from Volume up and Volume down key in an iOS.
I will show Android Code for Unity, help me with iOS code.
public int GetVolume()
{
if (Application.platform == RuntimePlatform.Android)
{
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject context = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass audioManagerClass = new
AndroidJavaClass("android.media.AudioManager");
AndroidJavaClass contextClass = new AndroidJavaClass("android.content.Context");
int AudioManager_STREAM_MUSIC = audioManagerClass.GetStatic<int>("STREAM_MUSIC");
string Context_AUDIO_SERVICE = contextClass.GetStatic<string>("AUDIO_SERVICE");
AndroidJavaObject audioService = context.Call<AndroidJavaObject>("getSystemService", Context_AUDIO_SERVICE);
return audioService.Call<int>("getStreamVolume", AudioManager_STREAM_MUSIC);
}
return 0;
}
Comment
Answer by LexGear · Jul 02, 2020 at 05:20 AM
I don't believe you have access to the input buttons on an iPhone. However, you might be able to get the current volume level (maaaaybe) and then check to see if it changes.