Unity calls Android Native method (one) to get Android system volume

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.