Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission Camera & androidStudio Build Error #473

Closed
KiDeokKim opened this issue Nov 26, 2019 · 13 comments
Closed

Permission Camera & androidStudio Build Error #473

KiDeokKim opened this issue Nov 26, 2019 · 13 comments

Comments

@KiDeokKim
Copy link

Hi, I'm trying to using your webview plugin.
it can be show webpage, but Can't show popup message(allow camera and microphone) and access permission camera.
so i read #360 , and download zip file, open android studio. (open file path is /plugins/Android )
but i see this error -
Gradle Sync Issues - ERROR: Cannot read packageName from C:\Users\Q\Desktop\unity-webview-master\plugins\Android\gradle_build\src\main\AndroidManifest.xml

can i get update plugin ? ( please update for access permission camera. current project can't access camera via webpage.)

@KojiNakamaru
Copy link
Member

Building the plugin for Android requires Unity's classes.jar so some special steps are required (cf. https://github.com/gree/unity-webview/tree/d380b1bb2564d73b55f169accb5135e3ee218a8d#how-to-build-webviewpluginjar ).
I however thought #360 was okay to be merged, so I merged it and updated binaries on the master branch. Though I haven't tested it, could you please try the latest?

@KiDeokKim
Copy link
Author

Thank you for your reply my comment. so i update from your plugin(just execute /dist in unity-webview.unitypackage) and build and run my project. not modify script.
but same state - can't show popup message(allow camera permission).
what I need to add my script? show this code in my script.

test address is #359 's address

WebViewObject webViewObject =
(new GameObject("WebViewObject")).AddComponent();
webViewObject.Init((msg) =>
{
Debug.Log(string.Format("CallFromJS[{0}]", msg));
});
webViewObject.LoadURL(address);
webViewObject.SetVisibility(true);

if i join from Computer browser(Chrome) above address, show popup message( are you allow camera permission? ).
but if i join from android unity project, it can't show popup message.
how can i show popup message for allow camera?

@KiDeokKim
Copy link
Author

KiDeokKim commented Nov 27, 2019

Okay, i finally success using webview - Video Chat. (tested from https://appr.tc/ , and add audio.)
but if i end video chat, using "SetVisibility(false)" , my camera rendering is stopped. maybe remain working on background apprtc...
and i tried to using "Destroy" component, unfortunately same state.
so how can i stop webview and restart rendering my camera?

@KojiNakamaru
Copy link
Member

The last code doesn't work if the target api is 23 or later, so I've fixed further in #477 and updated binaries. I'm not sure how you solved the issue for Video Chat, but a whole webview should be destroyed if you destroy the GameObject (cf.

var g = GameObject.Find("WebViewObject");
if (g != null) {
Destroy(g);
).

@KiDeokKim
Copy link
Author

KiDeokKim commented Nov 27, 2019

i read your reply, and Update from "unitypackage".
and If i access camera, my application turn off by force. your sample app also.(change url and tested).
maybe this phenomenon is wrong update. please check your updated binaries.
(I think this phenomenon is relation by camera permission.)

@KojiNakamaru
Copy link
Member

KojiNakamaru commented Nov 28, 2019

I tested for the sample app with the following setting.

image

and at least the app showed the page. Camera permission/feature is added to AndroidManifest.xml by defining UNITYWEBVIEW_ANDROID_ENABLE_CAMERA (cf. https://github.com/gree/unity-webview/tree/f5bff470041dd07f97a3f97d30fa03820a2af545#camera-permissionfeature ) as below.

image

Could you please tell me your environment? My environment is:

  • Unity 2019.2.3f12019.2.13f1
  • Nexus 7 (2013, Android 6.0.1)

@KiDeokKim
Copy link
Author

My environment is :

  • Unity 2019.2.6f1
  • RealWear HMT -1 (Android API is 8.1)
    and using Vuforia AR Camera.

so i follow your test.
capture

i tested not need Camera page(like https://www.google.com/ )
if i access google page, it's perfectly work.
but.. if i access need Camera Page, like above your test url, my application is shut down.

@KiDeokKim
Copy link
Author

Okay... I Think My Project is wrong..
I make new project, and Test Your plugin. and it's work... (but Can't see camera view. i don't know)
but if i destroy webviewobject, Unity camera is stopped.
how do i restart rendering Unity Camera?

@KojiNakamaru
Copy link
Member

The sample app has a button to destroy/create the webview:

if (GUI.Button(new Rect(600, 10, 80, 80), "*")) {
var g = GameObject.Find("WebViewObject");
if (g != null) {
Destroy(g);
} else {
StartCoroutine(Start());
}
}

By pressing this * button, the sample app shows the camera view again when the webview is recreated (I tested the sample app for https://davidwalsh.name/demo/camera.php with Unity 2019.2.6f1 -- BTW I typo'd my Unity version in #473 (comment) so I edited the comment).

If you want to stop/start the camera without destroying the webview, you might need to directly control the web content through EvaluateJS().

Also, it might be better to request the permission at start and/or just before creating the webview, as requesting the permission when the webview requests it may be too late (the webview continues to run while the permission dialog is displayed). The following is an example modification for the sample app.

diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs
index a62c1ca..a5efe9f 100644
--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -24,6 +24,9 @@ using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Networking;
 #endif
+#if !UNITY_EDITOR && UNITY_ANDROID
+using UnityEngine.Android;
+#endif
 
 public class SampleWebView : MonoBehaviour
 {
@@ -31,8 +34,29 @@ public class SampleWebView : MonoBehaviour
     public GUIText status;
     WebViewObject webViewObject;
 
+#if !UNITY_EDITOR && UNITY_ANDROID
+    bool inRequestingCameraPermission;
+
+    void OnApplicationFocus(bool hasFocus)
+    {
+        if (inRequestingCameraPermission && hasFocus) {
+            inRequestingCameraPermission = false;
+        }
+    }
+#endif
+
     IEnumerator Start()
     {
+#if !UNITY_EDITOR && UNITY_ANDROID
+        if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
+        {
+            inRequestingCameraPermission = true;
+            Permission.RequestUserPermission(Permission.Camera);
+        }        
+        while (inRequestingCameraPermission) {
+            yield return new WaitForSeconds(0.5f);
+        }
+#endif
         webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
         webViewObject.Init(
             cb: (msg) =>

If it is okay, I would like to revert 662142d as the above approach is more straightforward and doesn't require to include extra aar files.

@KiDeokKim
Copy link
Author

also consider my situation - i'm using Vuforia AR Camera, so Camera rendering is already use.
already use camera state, pressed button( so previous rendering camera is stopped and webview rendering camera(in video chat camera) is on. if you have enough time, tested it. )

so i asked 'how do i restart rendering Unity Camera?'
i don't test above your comments, that is helpful for me...? ( i will test your comment ASAP )
or using multiple camera( one is ARCamera, another is default camera), should i change my camera when I need each one?
thank you for comments and spending your time for me.

@KojiNakamaru
Copy link
Member

I have no experience about Vuforia, but it seems to have CameraDevice API:

https://library.vuforia.com/content/vuforia-library/en/reference/unity/classVuforia_1_1CameraDevice.html#aa70efaa4751ac6d5d54dce88fe725e0a

and there are some discussions about CameraDevice and VuforiaBehavior:

https://stackoverflow.com/questions/49925576/how-to-switch-change-front-and-back-vuforia-ar-camera-using-a-button/49975991#49975991
https://stackoverflow.com/questions/47000398/how-to-stop-vuforia-behaviour/58829640#58829640

These could be utilized to stop Vuforia and/or its camera before opening the webview and to restart Vuforia and/or its camera after closing the webview.

@KiDeokKim
Copy link
Author

KiDeokKim commented Nov 30, 2019

Finally successed VideoChat!. (I hope my project will be no errors next time.)
update your plugin and if i start VideoChat(start Visible true webView), stop ARCamera.
and if i end VideoChat, Destroy WebviewComponent and start ARCamera.
also, my project is already access camera permission , so i don't have to set Define Symbols.
Maybe i think that before errer(if i start videochat, forced exit my app) is duplicate permission camera. maybe....

Thank you for your helpful mind and your spent time.

P.S. i think next update will added permission microphone. it just my idea.

@KojiNakamaru
Copy link
Member

KojiNakamaru commented Dec 2, 2019

P.S. i think next update will added permission microphone. it just my idea.

Thanks! I'll later add the permission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants