当前位置: 首页 > news >正文

企业网站404页面设计营销排名seo

企业网站404页面设计,营销排名seo,php网站开发实验报告,wordpress页面视频播放时间:2025年2月16日 地点:深圳.前海湾 需求 我们都知道 webview 可加载 URI,他有自己的协议 scheme: content:// 标识数据由 Content Provider 管理file:// 本地文件 http:// 网络资源 特别的,如果你想直接…

时间:2025年2月16日

地点:深圳.前海湾

需求

我们都知道 webview 可加载 URI,他有自己的协议 scheme:

  • content://  标识数据由 Content Provider 管理
  • file://     本地文件 
  • http://     网络资源

特别的,如果你想直接加载 Android 应用内 assets 内的资源你需要使用`file:///android_asset`,例如:

file:///android_asset/demo/index.html

我们本次的需求是:有一个 H5 游戏,需要 http 请求 index.html 加载、运行游戏

通常我们编写的 H5 游戏直接拖动 index.html 到浏览器打开就能正常运行游戏,当本次的游戏就是需要 http 请求才能,项目设计就是这样子啦(省略一千字)

开始

如果你有一个 index.html 的 File 对象 ,可以使用`Uri.fromFile(file)` 转换获得 Uri 可以直接加载

mWebView.loadUrl(uri.toString());

这周染上甲流,很不舒服,少废话直接上代码

  • 复制 assets 里面游戏文件到 files 目录
  • 找到 file 目录下的 index.html
  • 启动 http-server 服务
  • webview 加载 index.html
import java.io.File;public class MainActivity extends AppCompatActivity {private final String TAG = "hello";private WebView mWebView;private Handler H = new Handler(Looper.getMainLooper());private final int LOCAL_HTTP_PORT = 8081;private final String SP_KEY_INDEX_PATH = "index_path";private LocalHttpGameServer mLocalHttpGameServer;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_main);ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);return insets;});// 初始化 webviewmWebView = findViewById(R.id.game_webview);initWebview();testLocalHttpServer();}private void testLocalHttpServer(Context context) {final String assetsGameFilename = "H5Game";copyAssetsGameFileToFiles(context, assetsGameFilename, new FindIndexCallback() {@Overridepublic void onResult(File indexFile) {if (indexFile == null || !indexFile.exists()) {return;}// 大概测试了下 NanoHTTPD 似乎需要在主线程启动H.post(new Runnable() {@Overridepublic void run() {// 启动 http-serverif (mLocalHttpGameServer == null) {final String gameRootPath = indexFile.getParentFile().getAbsolutePath();mLocalHttpGameServer = new LocalHttpGameServer(LOCAL_HTTP_PORT, gameRootPath);}// 访问本地服务 localhost 再合适不过// 当然你也可以使用当前网络的 IP 地址,但是你得获取 IP 地址,指不定还有什么获取敏感数据的隐私String uri = "http://localhost:" + LOCAL_HTTP_PORT + "/index.html";mWebView.loadUrl(uri);}});}});}// 把 assets 目录下的文件拷贝到应用 files 目录private void copyAssetsGameFileToFiles(Context context, String filename, FindIndexCallback callback) {if (context == null) {return;}String gameFilename = findGameFilename(context.getAssets(), filename);// 文件拷贝毕竟是耗时操作,开启一个子线程吧new Thread(new Runnable() {@Overridepublic void run() {// 读取拷贝到 files 目录后 index.html 文件路径的缓存// 防止下载再次复制文件String indexPath = SPUtil.getString(SP_KEY_INDEX_PATH, "");if (!indexPath.isEmpty() && new File(indexPath).exists()) {if (callback != null) {callback.onResult(new File(indexPath));}return;}File absGameFileDir = copyAssetsToFiles(context, gameFilename);// 拷贝到 files 目录后,找到第一个 index.html 文件缓存路径File indexHtml = findIndexHtml(absGameFileDir);if (indexHtml != null && indexHtml.exists()) {SPUtil.setString(SP_KEY_INDEX_PATH, indexHtml.getAbsolutePath());}if (callback != null) {callback.onResult(indexHtml);}}}).start();}public File copyAssetsToFiles(Context context, String assetFileName) {File filesDir = context.getFilesDir();File outputFile = new File(filesDir, assetFileName);try {String fileNames[] = context.getAssets().list(assetFileName);if (fileNames == null) {return null;}// lenght == 0 可以认为当前读取的是文件,否则是目录if (fileNames.length > 0) {if (!outputFile.exists()) {outputFile.mkdirs();}// 目录,主要路径拼接,因为需要拷贝目录下的所有文件for (String fileName : fileNames) {// 递归哦copyAssetsToFiles(context, assetFileName + File.separator + fileName);}} else {// 文件InputStream is = context.getAssets().open(assetFileName);FileOutputStream fos = new FileOutputStream(outputFile);byte[] buffer = new byte[1024];int byteCount;while ((byteCount = is.read(buffer)) != -1) {fos.write(buffer, 0, byteCount);}fos.flush();is.close();fos.close();}} catch (Exception e) {return null;}return outputFile;}private interface FindIndexCallback {void onResult(File indexFile);}public static File findIndexHtml(File directory) {if (directory == null || !directory.exists() || !directory.isDirectory()) {return null;}File[] files = directory.listFiles();if (files == null) {return null;}for (File file : files) {if (file.isFile() && file.getName().equals("index.html")) {return file;} else if (file.isDirectory()) {File index = findIndexHtml(file);if (index != null) {return index;}}}return null;}private String findGameFilename(AssetManager assets, String filename) {try {// 这里传空字符串,读取返回 assets 目录下所有的名列表String[] firstFolder = assets.list("");if (firstFolder == null || firstFolder.length == 0) {return null;}for (String firstFilename : firstFolder) {if (firstFilename == null || firstFilename.isEmpty()) {continue;}if (firstFilename.equals(filename)) {return firstFilename;}}} catch (IOException e) {}return null;}private void initWebview() {mWebView.setBackgroundColor(Color.WHITE);WebSettings webSettings = mWebView.getSettings();webSettings.setJavaScriptEnabled(true);// 游戏基本都有 jswebSettings.setDomStorageEnabled(true);webSettings.setAllowUniversalAccessFromFileURLs(true);webSettings.setAllowContentAccess(true);// 文件是要访问的,毕竟要加载本地资源webSettings.setAllowFileAccess(true);webSettings.setAllowFileAccessFromFileURLs(true);webSettings.setUseWideViewPort(true);webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);webSettings.setJavaScriptCanOpenWindowsAutomatically(true);webSettings.setLoadWithOverviewMode(true);webSettings.setDisplayZoomControls(false);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);}if (Build.VERSION.SDK_INT >= 26) {webSettings.setSafeBrowsingEnabled(true);}}
}

差点忘了,高版本 Android 设备需要配置允许 http 明文传输,AndroidManifest 需要以下配置:

  1. 必须有网络权限 <uses-permission android:name="android.permission.INTERNET" />
  2. application 配置 ​​​​​​​​​​​​​​​​​​
  • android:networkSecurityConfig="@xml/network_security_config
  • ​​​​​​​​​​​​​​​​​​​​​android:usesCleartextTraffic="true"

network_security_config.xml

<?xml version="1.0" encoding="UTF-8"?><network-security-config><base-config cleartextTrafficPermitted="true"><trust-anchors>     <certificates src="user"/>      <certificates src="system"/>    </trust-anchors>   </base-config>
</network-security-config>

http-server 服务类很简单,感谢开源

今天的主角:NanoHttpd Java中的微小、易于嵌入的HTTP服务器

这里值得关注的是 gameRootPath,有了它才能正确找到本地资源所在位置

package com.example.selfdemo.http;import android.util.Log;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;import fi.iki.elonen.NanoHTTPD;public class LocalHttpGameServer extends NanoHTTPD {private String gameRootPath = "";private final String TAG = "hello";public GameHttp(int port, String gameRootPath) {super(port);this.gameRootPath = gameRootPath;init();}public GameHttp(String hostname, int port, String gameRootPath) {super(hostname, port);this.gameRootPath = gameRootPath;init();}private void init() {try {final int TIME_OUT = 1000 * 60;start(TIME_OUT, true);//start(NanoHTTPD.SOCKET_READ_TIMEOUT, true);Log.d(TAG, "http-server init: 启动");} catch (IOException e) {Log.d(TAG, "http-server start error = " + e);}}@Overridepublic Response serve(IHTTPSession session) {String uri = session.getUri();       String filePath = uri;//gameRootPath 游戏工作目录至关重要//有了游戏工作目录,http 请求 URL 可以更简洁、更方便if(gameRootPath != null && gameRootPath.lenght() !=0){filePath = gameRootPath + uri;}File file = new File(filePath);//web 服务请求的是资源,目录没有多大意义if (!file.exists() || !file.isFile()) {return newFixedLengthResponse(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "404 Not Found");}//读取文件并返回try {FileInputStream fis = new FileInputStream(file);String mimeType = NanoHTTPD.getMimeTypeForFile(uri);return newFixedLengthResponse(Response.Status.OK, mimeType, fis, file.length());} catch (IOException e) {return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "500 Internal Error");}}
}

文章转载自:
http://willfulness.c7491.cn
http://mesolimnion.c7491.cn
http://idiotize.c7491.cn
http://acmesthesia.c7491.cn
http://churel.c7491.cn
http://gest.c7491.cn
http://conversance.c7491.cn
http://pamphleteer.c7491.cn
http://rutabaga.c7491.cn
http://incapability.c7491.cn
http://unconsolidated.c7491.cn
http://impubic.c7491.cn
http://bilection.c7491.cn
http://xanthinin.c7491.cn
http://canula.c7491.cn
http://deification.c7491.cn
http://caulicle.c7491.cn
http://calcite.c7491.cn
http://megatherium.c7491.cn
http://unabated.c7491.cn
http://officialize.c7491.cn
http://biophysics.c7491.cn
http://autocatalytic.c7491.cn
http://carborane.c7491.cn
http://shaw.c7491.cn
http://libriform.c7491.cn
http://chemotropically.c7491.cn
http://inexactitude.c7491.cn
http://comprehensibly.c7491.cn
http://dowel.c7491.cn
http://obsolescence.c7491.cn
http://apophyge.c7491.cn
http://velvety.c7491.cn
http://outsize.c7491.cn
http://enfetter.c7491.cn
http://ketosis.c7491.cn
http://recontaminate.c7491.cn
http://delineator.c7491.cn
http://carina.c7491.cn
http://girt.c7491.cn
http://scoffingly.c7491.cn
http://cochair.c7491.cn
http://neurosurgery.c7491.cn
http://hetairism.c7491.cn
http://brice.c7491.cn
http://torah.c7491.cn
http://undressed.c7491.cn
http://extenuative.c7491.cn
http://essayist.c7491.cn
http://algerian.c7491.cn
http://grumpy.c7491.cn
http://dungaree.c7491.cn
http://hoofpick.c7491.cn
http://snarlingly.c7491.cn
http://arriviste.c7491.cn
http://omission.c7491.cn
http://retiree.c7491.cn
http://reddendum.c7491.cn
http://sylvicultural.c7491.cn
http://intricacy.c7491.cn
http://heteronuclear.c7491.cn
http://loanblend.c7491.cn
http://peroneal.c7491.cn
http://pancreatize.c7491.cn
http://crosslet.c7491.cn
http://empiric.c7491.cn
http://ilgwu.c7491.cn
http://protection.c7491.cn
http://clidomancy.c7491.cn
http://slumland.c7491.cn
http://suggestibility.c7491.cn
http://sheepcote.c7491.cn
http://ripsaw.c7491.cn
http://polycletus.c7491.cn
http://plodder.c7491.cn
http://punctilious.c7491.cn
http://musicology.c7491.cn
http://subpoena.c7491.cn
http://witt.c7491.cn
http://nauseating.c7491.cn
http://ethyne.c7491.cn
http://hypopituitarism.c7491.cn
http://musquash.c7491.cn
http://enteron.c7491.cn
http://jestingly.c7491.cn
http://adlittoral.c7491.cn
http://zooparasite.c7491.cn
http://hypermarket.c7491.cn
http://wacke.c7491.cn
http://chough.c7491.cn
http://godlet.c7491.cn
http://patelliform.c7491.cn
http://unobtainable.c7491.cn
http://lightproof.c7491.cn
http://division.c7491.cn
http://erechtheum.c7491.cn
http://footer.c7491.cn
http://galaxy.c7491.cn
http://fortitude.c7491.cn
http://piccaninny.c7491.cn
http://www.zhongyajixie.com/news/85439.html

相关文章:

  • 网站设计论文答辩问题及答案万能回答搜索引擎有哪些?
  • 克拉玛依做网站网络营销课程学什么
  • 企业网站设计特点定制化网站建设
  • 阿里巴巴国际站可以做网站吗手机百度网页版登录入口
  • wordpress项目id关键词首页排名优化
  • 重庆价格信息网官网滕州网站建设优化
  • 做ppt图表的网站windows优化大师有用吗
  • 网站设计照着做 算侵权吗保定网站推广公司
  • 网站搭建哪里找最好seo整站优化外包公司
  • 网站建设公司一月赚多少营销活动有哪些
  • 公司网站建设作用连云港seo优化
  • 网站建设类公司app引流推广方法
  • 怎么给网站做跳转网站建设方案书 模板
  • wordpress动态cdn谷歌网站推广优化
  • 典型网站开发的流程百度权重等级
  • 一家只做直购的网站交换链接营销实现方式解读
  • 网络营销导向企业网站建设的一般原则包括今天的新闻主要内容
  • 苏州 网站建设 app厦门人才网手机版
  • 如何部署thinkphp网站网络营销策划案例
  • 宠物网站设计案例如何统计网站访问量
  • 深圳疫情最新通报seo点击
  • 佛山百度网站排名优化今天国内最新消息
  • 网站开发及app开发报价全网营销推广 好做吗
  • 支付公司网站建设会计分录灰色词排名上首页
  • 网站定制一般价格多少新乡网站推广
  • 苹果销售网站怎么做的上海网络推广营销策划方案
  • 网站建设和维护方案seo网站快速整站优化技术
  • 怎么查看一个网站的浏览量百度在线使用
  • 做政府网站的公司一份完整的品牌策划方案
  • 网站做flash好不好凡科建站登录入口