diff --git a/README.md b/README.md index 8100f54b..21552ca1 100644 --- a/README.md +++ b/README.md @@ -163,15 +163,22 @@ implementation will adjust Unity's SurfaceView z order. Please refer and `plugins/Android/src/net/gree/unitywebview/CUnityPlayer.java` if you already have your own activity implementation. -#### Camera Permission/Feature +#### Camera/Audio Permission/Feature -In order to allow camera access (`navigator.mediaDevices.getUserMedia({ video:true })`), please define `UNITYWEBVIEW_ANDROID_ENABLE_CAMERA` so that `Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs` adds the followings to `AndroidManifest.xml`. +For allowing camera access (`navigator.mediaDevices.getUserMedia({ video:true })`), please define `UNITYWEBVIEW_ANDROID_ENABLE_CAMERA` so that `Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs` adds the followings to `AndroidManifest.xml`. ```xml ``` +For allowing microphone access (`navigator.mediaDevices.getUserMedia({ audio:true })`), please define `UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE` so that `Assets/Plugins/Editor/UnityWebViewPostprocessBuild.cs` adds the followings to `AndroidManifest.xml`. + +```xml + + +``` + Details for each Unity version are the same as for hardwareAccelerated. Please also note that it is necessary to request permissions at runtime for Android API 23 or later as below: ```diff diff --git a/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java b/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java index 198aa78f..2f5fd5b4 100644 --- a/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java +++ b/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java @@ -163,11 +163,14 @@ public void Init(final String gameObject, final boolean transparent, final Strin public void onPermissionRequest(final PermissionRequest request) { final String[] requestedResources = request.getResources(); for (String r : requestedResources) { - if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) { + if (r.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE) || r.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) { request.grant(requestedResources); // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // a.runOnUiThread(new Runnable() {public void run() { - // final String[] permissions = { "android.permission.CAMERA" }; + // final String[] permissions = { + // "android.permission.CAMERA", + // "android.permission.RECORD_AUDIO", + // }; // ActivityCompat.requestPermissions(a, permissions, 0); // }}); // } diff --git a/plugins/Editor/UnityWebViewPostprocessBuild.cs b/plugins/Editor/UnityWebViewPostprocessBuild.cs index 72139c32..dd107ca1 100644 --- a/plugins/Editor/UnityWebViewPostprocessBuild.cs +++ b/plugins/Editor/UnityWebViewPostprocessBuild.cs @@ -25,6 +25,9 @@ public void OnPostGenerateGradleAndroidProject(string basePath) { changed = (androidManifest.SetHardwareAccelerated(true) || changed); #if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA changed = (androidManifest.AddCamera() || changed); +#endif +#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE + changed = (androidManifest.AddMicrophone() || changed); #endif if (changed) { androidManifest.Save(); @@ -69,6 +72,9 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { #if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA changed = (androidManifest.AddCamera() || changed); #endif +#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE + changed = (androidManifest.AddMicrophone() || changed); +#endif #if UNITY_5_6_0 || UNITY_5_6_1 changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed); #endif @@ -176,4 +182,21 @@ internal bool AddCamera() { } return changed; } + + internal bool AddMicrophone() { + bool changed = false; + if (SelectNodes("/manifest/uses-permission[@android:name='android.permission.MICROPHONE']", nsMgr).Count == 0) { + var elem = CreateElement("uses-permission"); + elem.Attributes.Append(CreateAndroidAttribute("name", "android.permission.MICROPHONE")); + ManifestElement.AppendChild(elem); + changed = true; + } + if (SelectNodes("/manifest/uses-feature[@android:name='android.hardware.microphone']", nsMgr).Count == 0) { + var elem = CreateElement("uses-feature"); + elem.Attributes.Append(CreateAndroidAttribute("name", "android.hardware.microphone")); + ManifestElement.AppendChild(elem); + changed = true; + } + return changed; + } }