452233108 发表于 2022-1-8 16:07:21

越来越多的开发者热衷于使用html5+开发移动WebApp

越来越多的开发者热衷于使用 html5+ 来开发移动 web 应用程序。不过html封装app,HTML5 Web APP的出现能否在未来替代移动应用天外神坛,还是个未知数。一方面,用户在使用习惯上不喜欢在浏览器上输入复杂的网址;另一方面,Html5 Web App存储在服务器端,每次使用都需要进行数据传输,会造成流量浪费。有些开发者不想接触复杂的 JAVA 代码,那么使用 HTMl5 开发应用程序并简单地封装成 APK 文件的方法是什么?

SDK 中的 一、

1.将组件实例化为: = new (this);

2. 调用的 () 方法设置要显示的网页:

互联网使用:.("");

对于本地文件:.("file:////XX.html"); 本地文件存放在:file

调用 3.( ) 方法来显示 Web 视图

4.查看了很多带有点击链接的页面后html封装app,为了支持回退功能,需要重写类的()方法。如果不做任何处理,点击系统后退键,整个浏览器会调用()并自行结束,而不是回到上一页

5.需要在.xml文件中添加权限,否则会出现网页不报错。

http://tt.ccoox.cn/data/attachment/forum/20220108/1641629241720_1.png

缺点:如果是加载正常的网页,没有问题,但是如果是html5,封装后在.3以上,.2及以下都可以正常访问,SDK不完全支持HTML5

以下是具体示例:

.java

<p><pre>    <span style="color: rgba(0, 0, 0, 1)">package com.android.webview.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> MainActivity extends Activity {
    </span><span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> WebView webview;
    @Override
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">实例化WebView对象</span>
      webview = <span style="color: rgba(0, 0, 255, 1)">new</span> WebView(<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">设置WebView属性,能够执行Javascript脚本</span>
      webview.getSettings().setJavaScriptEnabled(<span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">);
      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">加载需要显示的网页</span>
      webview.loadUrl(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http://www.31358.cn/</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">设置Web视图</span>
<span style="color: rgba(0, 0, 0, 1)">      setContentView(webview);
    }
    @Override
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">设置回退
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> boolean onKeyDown(<span style="color: rgba(0, 0, 255, 1)">int</span> keyCode, KeyEvent <span style="color: rgba(0, 0, 255, 1)">event</span><span style="color: rgba(0, 0, 0, 1)">) {
      </span><span style="color: rgba(0, 0, 255, 1)">if</span> ((keyCode == KeyEvent.KEYCODE_BACK) &&<span style="color: rgba(0, 0, 0, 1)"> webview.canGoBack()) {
            webview.goBack(); </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">goBack()表示返回WebView的上一页面</span>
            <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
      }
      </span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
} </span></pre></p>
在 .xml 文件中添加权限

<p><pre>    <?xml version=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">1.0</span><span style="color: rgba(128, 0, 0, 1)">"</span> encoding=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">utf-8</span><span style="color: rgba(128, 0, 0, 1)">"</span>?>
<manifest xmlns:android=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http://schemas.android.com/apk/res/android</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
      package</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">com.android.webview.activity</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
      android:versionCode</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">1</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
      android:versionName</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">1.0</span><span style="color: rgba(128, 0, 0, 1)">"</span>>
    <uses-sdk android:minSdkVersion=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">10</span><span style="color: rgba(128, 0, 0, 1)">"</span> />
    <application android:icon=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">@drawable/icon</span><span style="color: rgba(128, 0, 0, 1)">"</span> android:label=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">@string/app_name</span><span style="color: rgba(128, 0, 0, 1)">"</span>>
      <activity android:name=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">.MainActivity</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
                  android:label</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">@string/app_name</span><span style="color: rgba(128, 0, 0, 1)">"</span>>
            <intent-filter>
                <action android:name=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">android.intent.action.MAIN</span><span style="color: rgba(128, 0, 0, 1)">"</span> />
                <category android:name=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">android.intent.category.LAUNCHER</span><span style="color: rgba(128, 0, 0, 1)">"</span> />
            </intent-filter>
      </activity>
    </application>
    <uses-permission android:name=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">android.permission.INTERNET</span><span style="color: rgba(128, 0, 0, 1)">"</span>/>
</manifest> </pre></p>
二、使用

是一个快速开发平台,用于创建基于 HTML、CSS 和 . 它使开发者能够充分利用 、Palm、WP7、Bada 和智能手机的核心功能——包括地理定位、加速度计、联系人、声音和振动等,此外还有丰富的插件可以扩展无限的功能。是免费的,但需要特定平台提供的附加软件,如SDK、SDK等,

详情请见:#

优点:添加了SDK,编程免费,完美适配不同设备的屏幕尺寸,适合高手使用。

缺点:没有使用布局,直接加载网页,无法添加广告。

三、使用在线生成

是一个开源开发平台,支持开发者以标准化的web开发模式,使用HTML5、CSS3、快速实现移动应用。将 HTML 将。您所要做的就是将完成的 HTML5 应用程序上传到服务器,很快,它就会被编译成一个标准的 APK 安装文件。

网站:

优点:一键生成,适合普通人学习

缺点:直接包装,无法加广告。

四、 在线生成的Html5 XDK(使用插件)
页: [1]
查看完整版本: 越来越多的开发者热衷于使用html5+开发移动WebApp