3
\$\begingroup\$

I'm developing a simple android app that needs to use the microphone. I'm able to load my app on my Android phone using developer mode, but I do not understand how to enable the mic. How can I enable the microphone and use the input?

I started with a brand new Unity 2D project. I created a TextMeshPro Text object to display logs and set this reference on the script via the inspector. I have attached the following script to the Main Camera.

using UnityEngine;
using UnityEngine.Android;
using TMPro;

public class RequestPermissionScript : MonoBehaviour
{
    public TextMeshProUGUI logs;

    void Start()
    {
        if (Permission.HasUserAuthorizedPermission(Permission.Microphone))
        {
            // The user authorized use of the microphone.
            logs.text = "has authorized";
        }
        else
        {
            // We do not have permission to use the microphone.
            // Ask for permission or proceed without the functionality enabled.
            logs.text = "has not authorized";
            Permission.RequestUserPermission(Permission.Microphone);

        }
    }
}

I then Build and Run this as Android and the app is loading on my Android phone attached via USB.

I expect a pop-up to appear asking for permissions to the mic, but this does not happen and the logs says "has not authorized". What am I missing or doing wrong?

\$\endgroup\$
  • \$\begingroup\$ i think you have array of microphones. base permissions is for android mobiles with single builting microphone devices. im not sure unity supports range of microphones but best solution is to use logcat to see logs of your device to see what is really happening or tools like realtime debugging to check your code on real device \$\endgroup\$ – virtouso Jan 12 at 17:21
-2
\$\begingroup\$

with this line the pop-up opens: Permission.RequestUserPermission(Permission.Microphone);

you have to include: using UnityEngine.Android;

Hope this helps...

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Game Development! Those lines are already included in the source code ... \$\endgroup\$ – Glorfindel May 17 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.