簡體   English   中英

未顯示來自Unity3d Android的WebView

[英]WebView from Unity3d Android is not shown

我正在嘗試從Android應用程序中顯示unity3d中的webview。 該測試的組件是:Android庫(有一個我出於測試目的而調用的方法):

public void nonStaticMethod() {
        Log.d("TAG", "Non-static method was called from my android class");
        String url = "http://roadtoautomation.blogspot.ro/2014/02/road-to-setup-and-create-first-appium.html";
        Toast.makeText(mContext, "URL: " + url, Toast.LENGTH_SHORT).show();

        webView = new WebView(mContext);
        Log.d("Interstitialactivity", "webView: " + webView);
        Toast.makeText(mContext, "webView: " + webView, Toast.LENGTH_SHORT).show();

        webView.loadUrl(url); // webview is not null

    }

來自類的Mono代碼:

using (AndroidJavaClass javaInterClass = new AndroidJavaClass("mypackage.MyActivity")) {
            if (javaInterClass != null) {
            Debug.Log ("MyActivity class is NOT null");

            try {
                Debug.Log ("before my activity");
                javaInterClass.Call ("nonStaticMethod");
                Debug.Log ("after my activity");
            } catch (Exception e) {
                Debug.Log ("exception");
                Console.WriteLine (e);
            }

        } else {
            Debug.Log ("MyActivity class is null");
        }
    }

從上面的代碼中,我可以看到android類不是null,但是未顯示webview(來自此“ javaInterClass.Call(” nonStaticMethod“);”)。

我是否必須在unity3d中添加插件以支持Webview? 謝謝。

如果您想通過Unity的用戶界面打開webview,則需要一個活動,或者您需要覆蓋unity的活動,否則您可以嘗試此操作

Uri uri = Uri.parse("http://www.example.com"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);

但它與Unity的Application.LoadUrl(url)相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM