Learn Lei Feng, a good example, the next tutorial in this series, will be through unity to achieve some of the common features of the Android side,
It is important not to refer to the jar package or the AAR package in the Asset/plugins/android directory.
1 usingSystem.Collections;2 usingSystem.Collections.Generic;3 usingUnityengine;4 5 Public classVolume:monobehaviour {6 7 8 Private Const stringCurrentvolume ="Getstreamvolume";//Current Volume9 Private Const stringMaxvolume ="Getstreammaxvolume";//Maximum VolumeTen One Private Const intStream_voice_call =0; A Private Const intStream_system =1; - Private Const intStream_ring =2; - Private Const intStream_music =3; the Private Const intStream_alarm =4; - Private Const intStream_notification =5; - Const intSTREAM_DTMF =8; - + //create several "3D Text" to receive the volume value - PublicTextmesh Stream_voice_call_text; + PublicTextmesh Stream_system_text; A PublicTextmesh Stream_ring_text; at PublicTextmesh Stream_music_text; - PublicTextmesh Stream_alarm_text; - PublicTextmesh Stream_notification_text; - PublicTextmesh Stream_dtmf_text; - - in Private StaticAndroidjavaobject Audiomanager; - to + voidAwake () - { theAndroidjavaclass Unityplayer =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer"); *Androidjavaobject currentactivity = unityplayer.getstatic<androidjavaobject> ("currentactivity"); $Audiomanager = currentactivity.call<androidjavaobject> ("Getsystemservice",NewAndroidjavaobject ("java.lang.String","Audio"));Panax Notoginseng } - voidUpdate () the { + // //Current Volume value A //Stream_voice_call_text.text = audiomanager.call<int> (Currentvolume, Stream_voice_call). ToString (); the //Stream_system_text.text = audiomanager.call<int> (Currentvolume, Stream_system). ToString (); + //Stream_ring_text.text = audiomanager.call<int> (Currentvolume, stream_ring). ToString (); - //Stream_music_text.text = audiomanager.call<int> (Currentvolume, Stream_music). ToString (); $ //Stream_alarm_text.text = audiomanager.call<int> (Currentvolume, Stream_alarm). ToString (); $ //Stream_notification_text.text = audiomanager.call<int> (Currentvolume, stream_notification). ToString (); - //Stream_dtmf_text.text = audiomanager.call<int> (Currentvolume, STREAM_DTMF). ToString (); - the //Max Volume Value -Stream_voice_call_text.text = audiomanager.call<int>(Maxvolume, Stream_voice_call). ToString ();WuyiStream_system_text.text = audiomanager.call<int>(Maxvolume, Stream_system). ToString (); theStream_ring_text.text = audiomanager.call<int>(Maxvolume, stream_ring). ToString (); -Stream_music_text.text = audiomanager.call<int>(Maxvolume, Stream_music). ToString (); WuStream_alarm_text.text = audiomanager.call<int>(Maxvolume, Stream_alarm). ToString (); -Stream_notification_text.text = audiomanager.call<int>(Maxvolume, stream_notification). ToString (); AboutStream_dtmf_text.text = audiomanager.call<int>(Maxvolume, STREAM_DTMF). ToString (); $ - } -}
Unity calls Android Native method (one) to get Android system volume