引导页

package com.example.pack;import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;public class SplashActivity extends AppCompatActivity {private final int SPLASH_DISPLAY_LENGHT = 2000;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_splash);new Handler().postDelayed(new Runnable() {@Overridepublic void run() {Intent intent = new Intent(SplashActivity.this, MainActivity.class);SplashActivity.this.startActivity(intent);SplashActivity.this.finish();}}, SPLASH_DISPLAY_LENGHT);}
}

WebView页面(加载H5)

package com.example.pack;import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;public class MainActivity extends AppCompatActivity {private WebView webView;//获取图片声明的变量private static final String TAG = MainActivity.class.getSimpleName();private String mCM;private ValueCallback<Uri> mUM;private ValueCallback<Uri[]> mUMA;private final static int FCR = 1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);webView = (WebView) findViewById(R.id.webView);WebSettings webSettings = webView.getSettings();//设置WebView属性,能够执行Javascript脚本webSettings.setJavaScriptEnabled(true);//如果访问的页面中有Javascript,则webview必须设置支持Javascript//设置可以访问文件webSettings.setAllowFileAccess(true);//设置支持缩放webSettings.setBuiltInZoomControls(true);webView.loadUrl("http://网址"); //https也可以//开启数据库缓存和 DOM 缓存webSettings.setAppCacheEnabled(true); //缓存路径webSettings.setDomStorageEnabled(true);webSettings.supportMultipleWindows();//获取WebView是否支持多窗口的值。webSettings.setAllowContentAccess(true);//是否允许在WebView中访问内容URL(Content Url),默认允许。内容Url访问允许WebView从安装在系统中的内容提供者载入内容。webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);//设置布局,会引起WebView的重新布局(relayout),默认值NARROW_COLUMNS/** WebView是否支持HTML的“viewport”标签或者使用wide viewport。* 设置值为true时,布局的宽度总是与WebView控件上的设备无关像素(device-dependent pixels)宽度一致。* 当值为true且页面包含viewport标记,将使用标签指定的宽度。* 如果页面不包含标签或者标签没有提供宽度,那就使用wide viewport。* */webSettings.setUseWideViewPort(true);/*是否允许WebView度超出以概览的方式载入页面,默认false。即缩小内容以适应屏幕宽度。该项设置在内容宽度超出WebView控件的宽度时生效,例如当getUseWideViewPort() 返回true时。*/webSettings.setLoadWithOverviewMode(true);/** API18以上版本已废弃。未来版本将不支持保存WebView中的密码。设置WebView是否保存密码,默认true* */
//        webSettings.setSavePassword(true);/** WebView是否保存表单数据,默认值true。* */
//        webSettings.setSaveFormData(true);/** 让JavaScript自动打开窗口,默认false。适用于JavaScript方法window.open()。* */webSettings.setJavaScriptCanOpenWindowsAutomatically(true);/** WebView是否下载图片资源,默认为true。* 注意,该方法控制所有图片的下载,包括使用URI嵌入的图片(使用setBlockNetworkImage(boolean)* 只控制使用网络URI的图片的下载)。* 如果该设置项的值由false变为true,WebView展示的内容所引用的所有的图片资源将自动下载。* */
//        webSettings.setLoadsImagesAutomatically(true);webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不使用缓存,只从网络获取数据。:// 支持中文,否则页面中中文显示乱码webSettings.setDefaultTextEncodingName("GBK");/*setWebChromeClient辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等如果不设置这个,JS代码中的按钮会显示,但是按下去却不弹出对话框 alert等*/
//        webView.setWebChromeClient(new WebChromeClient());webView.setWebChromeClient(new WebChromeClient() {/*判断页面加载过程*//*@Overridepublic void onProgressChanged(WebView view, int newProgress) {// TODO Auto-generated method stubif (newProgress == 100) {// 网页加载完成} else {// 加载中}}*///            获取图片//For Android 3.0+public void openFileChooser(ValueCallback<Uri> uploadMsg) {mUM = uploadMsg;Intent i = new Intent(Intent.ACTION_GET_CONTENT);i.addCategory(Intent.CATEGORY_OPENABLE);i.setType("*/*");MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FCR);}// For Android 3.0+, above method not supported in some android 3+ versions, in such case we use thispublic void openFileChooser(ValueCallback uploadMsg, String acceptType) {mUM = uploadMsg;Intent i = new Intent(Intent.ACTION_GET_CONTENT);i.addCategory(Intent.CATEGORY_OPENABLE);i.setType("*/*");MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Browser"),FCR);}//For Android 4.1+public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {mUM = uploadMsg;Intent i = new Intent(Intent.ACTION_GET_CONTENT);i.addCategory(Intent.CATEGORY_OPENABLE);i.setType("*/*");MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MainActivity.FCR);}//For Android 5.0+public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,WebChromeClient.FileChooserParams fileChooserParams) {if (mUMA != null) {mUMA.onReceiveValue(null);}mUMA = filePathCallback;Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {File photoFile = null;try {photoFile = createImageFile();takePictureIntent.putExtra("PhotoPath", mCM);} catch (IOException ex) {Log.e(TAG, "Image file creation failed", ex);}if (photoFile != null) {mCM = "file:" + photoFile.getAbsolutePath();takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));} else {takePictureIntent = null;}}Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);contentSelectionIntent.setType("*/*");Intent[] intentArray;if (takePictureIntent != null) {intentArray = new Intent[]{takePictureIntent};} else {intentArray = new Intent[0];}Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);startActivityForResult(chooserIntent, FCR);return true;}});/*安卓9.0新的限制 对未加密流量不在信任,直接放弃请求*///覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为,使网页用WebView打开webView.setWebViewClient(new WebViewClient() {//开始载入页面调用的,我们可以设定一个loading的页面,告诉用户程序在等待网络响应。
//            @Override
//            public void onPageStarted(WebView view, String url, Bitmap favicon) {
//
//            }//在页面加载结束时调用。我们可以关闭loading 条,切换程序动作。@Overridepublic void onPageFinished(WebView view, String url) {super.onPageFinished(view, url);view.setLayerType(view.LAYER_TYPE_HARDWARE, null);}@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);return true;}//加载https时候,需要加入 下面代码@Overridepublic void onReceivedSslError(WebView view,SslErrorHandler handler, SslError error) {handler.proceed();  //接受所有证书}/*@Overridepublic void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {//用javascript隐藏系统定义的404页面信息String data = "Page NO FOUND!";view.loadUrl("javascript:document.body.innerHTML=\"" + error + "\"");}*/});}//改写物理按键——返回的逻辑@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubif (keyCode == KeyEvent.KEYCODE_BACK) {if (webView.canGoBack()) {webView.goBack();//返回上一页面return true;} else {System.exit(0);//退出程序}}return super.onKeyDown(keyCode, event);}//销毁Webview@Overrideprotected void onDestroy() {if (webView != null) {webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);webView.clearHistory();((ViewGroup) webView.getParent()).removeView(webView);webView.destroy();webView = null;}super.onDestroy();}//获取图片文件@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent intent) {super.onActivityResult(requestCode, resultCode, intent);if (Build.VERSION.SDK_INT >= 21) {Uri[] results = null;//Check if response is positiveif (resultCode == Activity.RESULT_OK) {if (requestCode == FCR) {if (null == mUMA) {return;}if (intent == null) {//Capture Photo if no image availableif (mCM != null) {results = new Uri[]{Uri.parse(mCM)};}} else {String dataString = intent.getDataString();if (dataString != null) {results = new Uri[]{Uri.parse(dataString)};}}}}mUMA.onReceiveValue(results);mUMA = null;} else {if (requestCode == FCR) {if (null == mUM) return;Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();mUM.onReceiveValue(result);mUM = null;}}}// 创建图像文件private File createImageFile() throws IOException {@SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String imageFileName = "img_" + timeStamp + "_";File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);return File.createTempFile(imageFileName, ".jpg", storageDir);}}

参考:

  1. WebSettings说明
    https://blog.csdn.net/kevinscsdn/article/details/52241334;
  2. Input type=file 文件上传
    https://blog.csdn.net/u010615629/article/details/71809317;
  3. ERR_CLEARTEXT_NOT_PERMITTED
    https://blog.csdn.net/u010208471/article/details/84174126;
    https://blog.csdn.net/liang_duo_yu/article/details/84645066。

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.pack"><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.CAMERA" /><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.AppCompat.NoActionBar"android:usesCleartextTraffic="true"><!--解决启动界面黑白屏的方法--><activityandroid:name=".SplashActivity"android:launchMode="singleTask"android:theme="@style/Theme.AppStartLoadTranslucent"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".MainActivity"android:hardwareAccelerated="false"></activity></application></manifest>

参考:

  1. Android应用权限
    https://blog.csdn.net/true100/article/details/51644268

打包

Android Studio->Build->Build Bundle(s)/APK(s)->Build APK(s)

参考:

  1. https://blog.csdn.net/woaichimahua/article/details/54427528

Android使用WebView将网页打包成APP相关推荐

  1. php网站怎么打包成apk,Android编程实现webview将网页打包成apk的方法

    本文实例讲述了Android编程实现webview将网页打包成apk的方法.分享给大家供大家参考,具体如下: 功能非常简单,而且乍一看没什么特别大的用处,因为实际上就是浏览器而已...但如果说网页一开 ...

  2. cordova 把网页打包成app

    cordova 把网页打包成app 准备: 一:安装cordova 二:配置java环境 三:安装ADT 以下命令都是在控制台操作,依赖上面的三个环境 1.cordova create 文件夹- 包名 ...

  3. uniapp 将网页打包成app教程

    1.在uniapp里新建一个默认项目 2.创建完成后,找到根目录,打开page.json,将 {"pages": [ //pages数组中第一项表示应用启动页,参考:https:/ ...

  4. 物联网控制APP入门专题(三)---使用第三方平台将网页打包成APP

    摘要:前面的文章讲了如何用阿里云IoT Studio快速制作一个网页版的手机端,可以通过手机浏览器浏览制定的网址就能实现对物联网设备的控制.本文讲解通过第三方平台将这个网页打包成一个APK文件,安装到 ...

  5. (一)移动App开发——Native App-原生开发Web App-网页开发Hybrid App-混合开发网页打包成App四方式-Cordova-APPCan-DCloud-API Cloud

    移动 App 开发 Native App-原生开发 开发技术 原生的 Android 平台 原生的 iOS 平台 JavaScript bridge 用于原生应用中的 Web 和原生平台进行交互. h ...

  6. 设置网页打开默认全屏_网页打包成APP,macOS解锁刷少数派新姿势

    随着web端所能实现的功能.体验越来越完善,是否需要客户端成为网站管理者重新考虑的问题,尤其是对于一些资讯类信息流网站.例如少数派,移动端和桌面端网站的自适应做的非常完善,拥有iOS/Android双 ...

  7. 网页打包成app创建IOS免签app教程

    一键打包网址生成IOS免签App带绿标,支持动态更换网址,可按量付费可下载安装文件上传至自己服务器进行分发 创建前准备 1.域名一个 2.图标一个png格式 500KB以内,1024像素最佳 3.ap ...

  8. 如何把网页打包成app

    工具/原料 电脑 Hbuilder 方法/步骤 用Hbuilder新建一个APP项目,操作方法如下. 然后给这个APP项目设定项目名称,这样即可新建成功了. 新建的一个APP项目,里面有一些JS文件夹 ...

  9. 将Html网页或者是Aue项目打包成App

    把前端的网页打包成App 一. 前言 ​ 首先,在学前端的时候,我们接触到了Html,css,js,你只需要有这些,即可打包成一个App,当然肯定需要一些打包的软件,然后你如果学习到了Vue框架,用脚 ...

最新文章

  1. Sean Lynch谈Facebook Claspin监控工具的由来
  2. 《深入理解Java虚拟机》笔记4——类文件结构
  3. SAP在大中华区推出SAP数字化转型教育网络平台
  4. boost::graph::isomorphism用法的测试程序
  5. 梯度迭代树回归(GBDT)算法介绍及Spark MLlib调用实例(Scala/Java/python)
  6. 使用关键字创建具有局部作用域的JavaScript变量
  7. python绑定内核_向Ipython添加python2内核
  8. 写入文件python并用序号_Python和excel表合成示例:向表中添加序列号,向表的现有内容添加索引,与,Excel,表格,综合,实例,给,增加,序号,对,已有...
  9. Django简单介绍-基础1
  10. Python实战之SocketServer模块
  11. 编辑距离Edit distance
  12. 事实表和维度表是怎么造数据_数据库与数据仓库的那点事
  13. cad2017单段线_CAD制图规定-2017最新版.doc
  14. crash report for adobe photoshop cc 2019
  15. 片上总线Wishbone 学习(九)总线周期之单次读操作
  16. 信息学奥赛一本通(c++):1413:确定进制
  17. Arcgis中山脊线,山谷线的提取,以及流域的分割
  18. Python解决图文验证码登录识别(1)
  19. alt复制选区就会卡 ps_ps怎么复制选区相关常见问题解答
  20. 欧洲之星Fotona 4D是什么,欧洲之星Fotona 4和热玛吉哪个好

热门文章

  1. 以stc15w408as为核心,基于gsm的红外报警技术报告
  2. 一行 Python 代码能实现什么丧心病狂的功能?
  3. 小米系列手机 开发者版本 之 USB安装出现当前设备已被临时限制
  4. 我的世界服务器怎么开启坐标显示,坐标 - Minecraft Wiki,最详细的官方我的世界百科...
  5. 领导者都具备的四大思维能力
  6. EXCEL中进行经纬度坐标排重
  7. CAD2016 画直线时第二点为相对坐标(相对第一个点的坐标),非绝对坐标
  8. 2021-03-13 java八大基本数据类型
  9. 前置:API:DSP:核心交换机:边界网关协议:边界:(防御)防火墙:负载均衡:摆渡机:名词解释
  10. Windows Server 2012远程默认端口3389的修改