JGr*_*ray 8 java service android android-webview crosswalk
我正在努力用Crosswalk的实现替换Android应用中的原生webview.
我们已经能够使应用程序的大多数功能正常工作,但在服务中创建XWalkView仍然是我们试图通过的问题.创建Webview不是问题,但XWalkView需要使用活动上下文.如果这里的任何人遇到过这个问题,并且知道可能的解决方案或解决方法,我会非常感激.谢谢,如果您需要任何其他信息,请随时提出.
那么,什么是人行横道以及我为什么关心?看看网站: https: //crosswalk-project.org/
CrossWalk 是一个 HTML5 运行时,您可以使用它创建具有“本机功能”的 HTML5 应用程序 您可以使用 CrossWalk 为 Android(x86 和 Arm 架构)和 Tizen 创建纯 HTML5 应用程序,但您也可以使用 CrossWalk 作为安卓项目。
这意味着您可以用 XWalkView 替换 Android WebView 并获得一些额外的功能,例如:
-WebGl
-WebRTC
-网络音频
http://software.intel.com/en-us/html5/articles/crosswalk-application-runtime
如何在 Android 应用程序中嵌入 CrossWalk WebView(从现在开始是 XWalkView),以便在我的混合应用程序(具有 html5 功能的 Android Native)上拥有所有这些优点
首先你必须下载运行时:
https://crosswalk-project.org/#documentation/downloads
下载任意 Android(ARM) 版本。
文件内包含开始使用 html5 应用程序所需的一切。
对于此测试,我们需要在 Eclipse 中导入 xwalk-core-library 项目
创建一个带有基本 Activity 的新 Android 项目,将其与库链接起来,并将以下代码放入 Activity 中:
Run Code Online (Sandbox Code Playgroud)package com.example.xwalkwithlibrary; import org.xwalk.core.XWalkView; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.LinearLayout; public class XWalkEmbedLib extends Activity { private LinearLayout commentsLayout; private XWalkView xWalkWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_xwalk_embed_lib); commentsLayout=(LinearLayout)findViewById(R.id.principal); xWalkWebView = new XWalkView(this, this); xWalkWebView.load("file:///android_asset/www/index.html", null); commentsLayout.addView(xWalkWebView); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.xwalk_embed_lib, menu); return true; } }把它放在你的主布局上
Run Code Online (Sandbox Code Playgroud)<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".XWalkMain" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <LinearLayout android:id="@+id/principal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginLeft="35dp" android:layout_marginTop="86dp" android:orientation="vertical" > </LinearLayout> </RelativeLayout>最后在你的
/assets/www文件夹中放入你的 html 内容,就是这样
| 归档时间: |
|
| 查看次数: |
736 次 |
| 最近记录: |