【问题标题】:how to display a webpage in webview on pepper robo tablet如何在 Pepper robo 平板电脑的 webview 中显示网页
【发布时间】:2019-05-28 12:11:09
【问题描述】:

我正在尝试在胡椒机器人平板电脑的 webview 中显示网页。

在一个正在进行的项目中,已经使用按钮创建了 html 页面。当用户点击按钮时,我想在 webview 中显示“https://www.ebay.com/”网页。

它是机器人平台NAOqi与Android平板电脑连接,用户可以通过触摸点击按钮。

我创建了带有按钮和 webview 标签的 main.xml 文件 为按钮 onclick 创建了 Activity 为 webview 创建了另一个 Activity。

//bill.html page

<table class="billtab">


     <tbody>
            <tr>
                <td align="center">

                    <div id="mPay" class="buttonstyle" 
onclick="goToLoginPage();">mPay</div>
                </td>
                <td align="center">                        
                    <div id="ePay" class="buttonstyle" >Pay by ePay</div>                   
                </td>
             </tr>
    </tbody>
        </table>

--------------------------

/main.xml file

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
        android:id="@+id/ePay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Go to https://www.epay.com/"
        />

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

------------------------------------

//MainActivity.java

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    private Button button;

    public void onCreate(Bundle savedInstanceState) {
        final Context context = this;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button = (Button) findViewById(R.id.ePay);
        button.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View arg0) {
            Intent intent = new Intent(context, WebViewActivity.class);
            startActivity(intent);
          }
        });
    }
}
------------------------------

//webviewactivity.java

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class WebViewActivity extends Activity {

            private WebView webView;
            public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);
            webView = (WebView) findViewById(R.id.webView1);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("https://www.epay.com/");

    }
}
-------------------------------

在 Pepper robo 平板电脑上,网页应显示在 webview 中

【问题讨论】:

  • 您使用的是什么版本的机器人?您使用的是 Android QiSDK 还是 Choregraph?您是否必须在平板电脑上安装 Android 应用程序或通过 choregraph/python 打开网站也是一种选择?
  • NAOqi 版本 2.5.10.7 -- 我正在使用 choregraph -- 当用户点击按钮时,我可以通过 choregraph 打开网站(使用 javascript window.open() 函数)。但是网页必须在 webview 中显示。由于 webview 是 Android 组件,如何在 Pepper android 平板电脑中显示.. 请提出解决方法。谢谢
  • 我认为该页面实际上已经显示在 webview 中。在 Choregraph 中,您调用了 ALTabletService::showWebview 或 ShowWebView Box?所以页面已经显示在 Webview 中。在那个 webview 中调用 window.open() 仍然是 webview ......你使用 android 编程的动机是什么?使用 2.5.10.7。它不受支持,可以用 choregraph/python/javascript 解决很多问题。

标签: android webview pepper


【解决方案1】:

如果您使用的是 NAOqi 2.5,您不需要进行任何 Android 开发,您可以为应用程序中托管的网页执行 ALTabletService.showWebview。有关这方面的更多文档,请参阅 using pepper's tablet,并参阅 robot-jumpstarter 了解一些这样做的例子。

在您的情况下,您可能会在本地托管页面(即,作为应用程序的一部分,托管在 Pepper 上并包含您的按钮)和 ebay 等外部页面之间进行切换。

【讨论】:

    猜你喜欢
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多