Android SDK Directory introduce

本文详细介绍了Android系统的架构组成,从应用程序、框架层到系统库、硬件抽象层等,覆盖了Android系统的主要组成部分及其功能。

这些都是基本包,它们是通过Android SDK来编写应用程序的基石,这里是从最底层到最高层列出并加以说明。

* android.util 包含一些底层辅助类,例如:特定的容器类,XML辅助工具类等。

* android.os 提供基本的操作服务,消息传递和进程间通信IPC。

* android.graphics 作为图形渲染包,提供图形渲染功能。

* android.text  android.text.method  android.text.style  android.text.util  提供一套丰富的文本处理工作,支持富文本,输入模式等。

* android.database 包含底层API处理数据库,方便操作数据库表和数据。

* android.content 提供各种服务访问数据在手机设备上,程序安装到手机设备和其他相关资源,以及内容提供展示动态数据。

* android.view  核心用户界面框架。

* android.widget 提供标准用户界面元素,List(列表),Buttons(按钮),Layout manager(布局管理器)等,是组成我们界面的基本元素。

* android.app 提供高层应用程序模型,实现使用Activity。

* android.provider 提供方便调用系统提供的content providers的接口。

* android.telephony 提供API和手机设备的通话接口。

* android.webikit 包含以系列工作在基于Web内容的API。

 

 

frameworks 目录 (核心框架——java及C++语言)
.
|-- base    (基本内容)
|   |-- api   (?都是xml文件,定义了java的api?)
|   |-- awt   (AWT库)
|   |-- build   (空的)
|   |-- camera   (摄像头服务程序库)
|   |-- cmds   (重要命令:am、app_proce等)
|   |-- core   (核心库)
|   |-- data   (字体和声音等数据文件)
|   |-- docs   (文档)
|   |-- graphics (图形相关)
|   |-- include   (头文件)
|   |-- keystore (和数据签名证书相关)
|   |-- libs   (库)
|   |-- location (地区库)
|   |-- media   (媒体相关库)
|   |-- obex   (蓝牙传输库)
|   |-- opengl   (2D-3D加速库)
|   |-- packages (设置、TTS、VPN程序)
|   |-- sax   (XML解析器)
|   |-- services (各种服务程序)
|   |-- telephony (电话通讯管理)
|   |-- test-runner (测试工具相关)
|   |-- tests   (各种测试)
|   |-- tools   (一些叫不上名的工具)
|   |-- vpn   (VPN)
|   `-- wifi   (无线网络)
|-- opt    (可选部分)
|   |-- com.google.android     (有个framework.jar)
|   |-- com.google.android.googlelogin   (有个client.jar)
|   `-- emoji   (standard message elements)
`-- policies   (Product policies are operating system directions aimed at specific uses)
    `-- base  
        |-- mid (MID设备)
        `-- phone (手机类设备,一般用这个)

hardware 目录   (部分厂家开源的硬解适配层HAL代码)
|-- broadcom    (博通公司)
|   `-- wlan    (无线网卡)
|-- libhardware    (硬件库)
|   |-- include    (头文件)
|   `-- modules   (Default (and possibly architecture dependents) HAL modules)
|       |-- gralloc   (gralloc显示相关)
|       `-- overlay   (Skeleton for the "overlay" HAL module.)
|-- libhardware_legacy (旧的硬件库)
|   |-- flashlight   (背光)
|   |-- gps    (GPS)
|   |-- include    (头文件)
|   |-- mount    (旧的挂载器)
|   |-- power    (电源)
|   |-- qemu    (模拟器)
|   |-- qemu_tracing (模拟器跟踪)
|   |-- tests    (测试)
|   |-- uevent    (uevent)
|   |-- vibrator    (震动)
|   `-- wifi    (无线)
|-- msm7k    (高通7k处理器开源抽象层)
|   |-- boot    (启动)
|   |-- libaudio   (声音库)
|   |-- libaudio-qsd8k (qsd8k的声音相关库)
|   |-- libcamera   (摄像头库)
|   |-- libcopybit   (copybit库)
|   |-- libgralloc   (gralloc库)
|   |-- libgralloc-qsd8k (qsd8k的gralloc库)
|   |-- liblights   (背光库)
|   `-- librpc    (RPC库)
|-- ril     (无线电抽象层)
|   |-- include    (头文件)
|   |-- libril    (库)
|   |-- reference-cdma-sms (cdma短信参考)
|   |-- reference-ril    (ril参考)
|   `-- rild     (ril后台服务程序)
`-- ti       (ti公司开源HAL)
    |-- omap3     (omap3处理器)
    |   |-- dspbridge   (DSP桥)
    |   |-- libopencorehw (opencore硬件库)
    |   |-- liboverlay   (overlay硬件库)
    |   |-- libstagefrighthw (stagefright硬件库)
    |   `-- omx    (omx组件)
    `-- wlan     (无线网卡)

prebuilt 目录    (x86和arm架构下预编译的一些资源)
.
|-- android-arm   (arm-android相关)
|   |-- gdbserver   (gdb调试器)
|   `-- kernel    (模拟的arm内核)
|-- android-x86   (x86-android相关)
|   `-- kernel    (空的)
|-- common    (通用编译好的代码,应该是java的)
|-- darwin-x86    (drawin x86平台)
|   `-- toolchain   (工具链)
|       |-- arm-eabi-4.2.1 
|       |-- arm-eabi-4.3.1 
|       `-- arm-eabi-4.4.0 
|-- darwin-x86_64   (drawin x86 64bit平台)
|-- linux-x86    (linux x86平台)
|   `-- toolchain   (工具链,我们应该主要用这个)
|       |-- arm-eabi-4.2.1 
|       |-- arm-eabi-4.3.1 
|       |-- arm-eabi-4.4.0 
|       `-- i686-unknown-linux-gnu-4.2.1 (x86版编译器)
|-- linux-x86_64   (linux x86 64bit平台)
|-- windows    (windows平台)
`-- windows-x86_64 (64bit windows平台)


system 目录   (底层文件系统库、应用及组件——C语言)
.
|-- Bluetooth   (蓝牙相关)
|-- core    (系统核心工具盒接口)
|   |-- adb   (adb调试工具)
|   |-- cpio   (cpio工具,创建img)
|   |-- debuggerd (调试工具)
|   |-- fastboot (快速启动相关)
|   |-- include   (系统接口头文件)
|   |-- init   (init程序源代码)
|   |-- libacc   (轻量级C编译器)
|   |-- libctest   (libc测试相关)
|   |-- libcutils (libc工具)
|   |-- liblog   (log库)
|   |-- libmincrypt (加密库)
|   |-- libnetutils (网络工具库)
|   |-- libpixelflinger (图形处理库)
|   |-- libsysutils (系统工具库)
|   |-- libzipfile (zip库)
|   |-- logcat   (查看log工具)
|   |-- logwrapper (log封装工具)
|   |-- mkbootimg (制作启动boot.img的工具盒脚本)
|   |-- netcfg   (网络配置netcfg源码)
|   |-- nexus   (google最新手机的代码)
|   |-- rootdir   (rootfs,包含一些etc下的脚本和配置)
|   |-- sh    (shell代码)
|   |-- toolbox   (toolbox,类似busybox的工具集)
|   `-- vold   (SD卡管理器)
|-- extras    (额外工具)
|   |-- latencytop (a tool for software developers ,identifying system latency happen)
|   |-- libpagemap (pagemap库)
|   |-- librank   (Java Library Ranking System库)
|   |-- procmem (pagemap相关)
|   |-- procrank (Java Library Ranking System相关)
|   |-- showmap (showmap工具)
|   |-- showslab (showslab工具)
|   |-- sound   (声音相关)
|   |-- su    (su命令源码)
|   |-- tests   (一些测试工具)
|   `-- timeinfo (时区相关)
`-- wlan    (无线相关)
    `-- ti    (ti网卡相关工具及库)


packages 目录
.
|-- apps     (应用程序库)
|   |-- AlarmClock   (闹钟)
|   |-- Bluetooth   (蓝牙)
|   |-- Browser   (浏览器)
|   |-- Calculator   (计算器)
|   |-- Calendar   (日历)
|   |-- Camera    (相机)
|   |-- CertInstaller   (在Android中安装数字签名,被调用)
|   |-- Contacts   (拨号(调用)、联系人、通话记录)
|   |-- DeskClock   (桌面时钟)
|   |-- Email    (Email)
|   |-- Gallery    (相册,和Camera类似,多了列表)
|   |-- Gallery3D   (?3D相册)
|   |-- GlobalSearch (为google搜索服务,提供底层应用)
|   |-- GoogleSearch (google搜索)
|   |-- HTMLViewer (浏览器附属界面,被浏览器应用调用,同时提供存储记录功能)
|   |-- IM    (即时通讯,为手机提供信号发送、接收、通信的服务)
|   |-- Launcher   (登陆启动项,显示图片框架等等图形界面)
|   |-- Launcher2   (登陆启动项,负责应用的调用)
|   |-- Mms    (?彩信业务)
|   |-- Music    (音乐播放器)
|   |-- PackageInstaller (安装、卸载程序的响应)
|   |-- Phone    (电话拨号程序)
|   |-- Provision   (预设应用的状态,使能应用)
|   |-- Settings   (开机设定,包括电量、蓝牙、设备信息、界面、wifi等)
|   |-- SoundRecorder (录音机,可计算存储所需空间和时间)
|   |-- Stk     (接收和发送短信)
|   |-- Sync    (空)   -------○1
|   |-- Updater   (空)
|   `-- VoiceDialer   (语音识别通话)
|-- inputmethods   (输入法)
|   |-- LatinIME   (拉丁文输入法)
|   |-- OpenWnn   (OpenWnn输入法)
|   `-- PinyinIME   (拼音输入法)
|-- providers    (提供器,提供应用程序、界面所需的数据)
|   |-- ApplicationsProvider   (应用程序提供器,提供应用程序启动项、更新等)
|   |-- CalendarProvider    (日历提供器)
|   |-- ContactsProvider    (联系人提供器)
|   |-- DownloadProvider   (下载管理提供器)
|   |-- DrmProvider    (创建和更新数据库时调用)
|   |-- GoogleContactsProvider (联系人提供器的子类,用以同步联系人)
|   |-- GoogleSubscribedFeedsProvider(设置信息提供器)
|   |-- ImProvider     (空)
|   |-- ManagementProvider   (空)
|   |-- MediaProvider    (媒体提供器,提供存储数据)
|   |-- TelephonyProvider   (彩信提供器)
|   |-- UserDictionaryProvider (用户字典提供器,提供用户常用字字典)
|   `-- WebSearchProvider   (空)
|-- services     
|   |-- EasService     (空)
|   `-- LockAndWipe    (空)
`-- wallpapers      (墙纸)
    |-- Basic      (基本墙纸,系统内置墙纸)
    |-- LivePicker     (选择动态壁纸)
    |-- MagicSmoke    (壁纸特殊效果)
    `-- MusicVisualization   (音乐可视化,图形随音乐而变化)

○1里面有一个隐藏的.git文件夹,内容都是一样的,没有有意义的代码,config看似乎是一个下载程序,因此认为这些文件夹下没有实质东西。


vendor 目录    (厂家定制内容)

|-- aosp     (android open source project)
|   `-- products   (一些板级规则)
|-- htc     (HTC公司)
|   |-- common-open (通用部分)
|   |   `-- akmd   (解压img用的工具)
|   |-- dream-open   (G1开放部分)
|   |-- prebuilt-open (预编译开放部分)
|   `-- sapphire-open (sapphire这款型号开放内容)
|-- pv-open    (没东西)
|-- qcom     (里面基本是空的)
`-- sample    (google提供的样例)
    |-- apps    (应用)
    |   |-- client   (用户)
    |   `-- upgrade (升级)
    |-- frameworks   (框架)
    |   `-- PlatformLibrary (平台库)
    |-- products   (产品)
    |-- sdk_addon   (sdk添加部分)
    `-- skins    (皮肤)
        `-- WVGAMedDpi (WVGA适用的图片)

<template> <view style="width: 100%;height: 100%;background-color: white;display: flex;justify-content: center;"> <view :style="'width: 96%;margin-top: '+statusBarHeight+'px;'"> <!-- 标题栏 --> <view style="height: 40px;display: flex;align-items: center;justify-content: center;"> <u-icon @click="goBack" name="arrow-left" color="black" size="19" :bold="true" style="position: absolute;left: 13px;"></u-icon> <span style="font-size: 18px;">产品详情</span> </view> <u-gap height="10px"></u-gap> <view style="display: flex; flex-direction: column; width: 100%;"> <view> <u-swiper :list="list2" keyName="image" showTitle img-mode="aspectFit" :autoplay="false" circular height="200px" style="width: 93%;padding: 0% 3%;"> </u-swiper> </view> <u-gap height="15px"></u-gap> <view style="width: 100%;"> <u-tabs :list="list1" :activeStyle="activeTabStyle" :inactiveStyle="inactiveTabStyle" lineColor="#16A1BA" :current="tabCurrent" @change="tabsChange"></u-tabs> </view> </view> <scroll-view scroll-y="true" scroll-x="true" :style="'height:' + scrollViewHeight +'px;'"> <view v-if="tabCurrent === 0"> <view v-html="introduce" class="rich-text-container"></view> </view> <view v-if="tabCurrent === 1"> <view v-html="parameter" class="rich-text-container"></view> </view> <view v-if="tabCurrent === 2"> <view v-for="(item, index) in documentList" :key="index" style="display: flex;justify-content: center;align-items: center;margin-top: 4%;"> <view v-if="item.documentType === 'pdf'"><u-image width="50px" height="50px" src="../../static/images/pdf.png"></u-image></view> <view v-if="item.documentType === 'doc' || item.documentType === 'docx'"><u-image width="50px" height="50px" src="../../static/images/word.jpg"></u-image></view> <view v-if="item.documentType === 'xlsx' || item.documentType === 'xls'"><u-image width="50px" height="50px" src="../../static/images/excel.jpg"></u-image></view> <view v-if="item.documentType === 'ppt' || item.documentType === 'pptx'"><u-image width="50px" height="50px" src="../../static/images/ppt.webp"></u-image></view> <view @click="downloadFile(item)" style="margin-left: 2%;font-size: 16px;color: #229EC7;text-decoration: underline;"> {{item.documentName || item.documentUrl.split('/').pop()}} <text style="font-size:12px;color:#999;">(点击下载)</text> </view> </view> </view> <view v-if="tabCurrent === 3"> <view v-for="(item, index) in videoList" :key="index" style="margin-top: 10px;padding: 10px;background-color: #f5f5f5;border-radius: 5px;"> <view style="font-size: 16px;margin-bottom: 5px;">视频 {{index + 1}}</view> <view @click="downloadVideo(item)" style="color: #229EC7;text-decoration: underline;"> 点击下载视频 ({{item.documentName || item.videoUrl.split('/').pop()}}) </view> <view v-if="item.error" style="color: red;font-size: 12px;margin-top: 5px;"> {{ item.error }} </view> </view> </view> </scroll-view> </view> </view> </template> <script> import { request } from "../../common/requset.js" import { systemInfo } from "../../mixin.js" export default { mixins: [systemInfo], data() { return { currentNum: 0, tabCurrent: 0, list1: [ { name: '设备介绍' }, { name: '设备参数' }, { name: '文档' }, { name: '视频' } ], list2: [], productForm: [], activeTabStyle: { color: '#229EC7', }, inactiveTabStyle: { color: '#929FB5', }, productDeivece: { name: '', }, path: process.env.VUE_APP_BASE_API || '', // 兼容未配置环境变量的情况 statusBarHeight: 0, windowHeight: 0, introduce: '', parameter: '', documentList: [], videoList: [], scrollViewHeight: 0, } }, onLoad() { this.productDeivece.name = uni.getStorageSync("productDevice"); this.getProductCurrent(); this.statusBarHeight = getApp().globalData.statusBarHeight; this.windowHeight = uni.getSystemInfoSync().windowHeight; // 计算滚动区域高度(兼容不同设备) this.scrollViewHeight = this.windowHeight - this.statusBarHeight - 265 - (uni.getSystemInfoSync().platform === 'h5' ? 0 : 44); // 调试日志:检查基础URL console.log('当前基础URL:', this.path); }, methods: { // 视频下载方法(优化版) async downloadVideo(item) { try { this.$set(item, 'error', null); const videoUrl = this.processVideoUrl(item.videoUrl); // 调试日志:输出完整视频URL console.log('尝试下载视频URL:', videoUrl); // 检查URL有效性 if (!videoUrl) throw new Error('视频URL为空'); if (!await this.checkUrlAvailable(videoUrl)) { throw new Error('视频资源不存在(404)'); } // 检查存储权限 const hasPermission = await this.checkStoragePermission(); if (!hasPermission) { // Android 10+ 特殊处理 if (uni.getSystemInfoSync().platform === 'android' && uni.getSystemInfoSync().sdkVersion >= '29') { await this.saveVideoToAlbumAndroid10Plus(videoUrl, item); return; } throw new Error('无存储权限,请前往设置开启'); } uni.showLoading({ title: '准备下载...', mask: true }); // 开始下载 const downloadResult = await this.startDownload(videoUrl); await this.saveVideoToAlbum(downloadResult.tempFilePath, item); uni.showToast({ title: '视频已保存到相册', icon: 'success', duration: 2000 }); } catch (error) { console.error('视频下载失败:', error); this.$set(item, 'error', this.getErrorMessage(error)); uni.showToast({ title: this.getErrorMessage(error), icon: 'none' }); } finally { uni.hideLoading(); } }, // 处理视频URL(兼容相对路径和绝对路径) processVideoUrl(rawUrl) { if (!rawUrl) return ''; // 处理以//开头的URL if (rawUrl.startsWith('//')) { return `https:${rawUrl}`; } // 处理相对路径 if (!rawUrl.startsWith('http')) { return `${this.path}${rawUrl.startsWith('/') ? rawUrl : '/' + rawUrl}`; } return rawUrl; }, // 检查URL是否可访问(HEAD请求) checkUrlAvailable(url) { return new Promise((resolve) => { uni.request({ url, method: 'HEAD', timeout: 5000, success: (res) => resolve(res.statusCode === 200), fail: () => resolve(false) }); }); }, // 通用下载方法(带进度提示) startDownload(url) { return new Promise((resolve, reject) => { const downloadTask = uni.downloadFile({ url, timeout: 45000, success: (res) => { if (res.statusCode === 200) { resolve(res); } else { reject(new Error(`服务器响应异常[${res.statusCode}]`)); } }, fail: (err) => { reject(new Error(`下载失败: ${err.errMsg}`)); } }); // 监听下载进度 downloadTask.onProgressUpdate((res) => { uni.showLoading({ title: `下载中 ${res.progress}%`, mask: true }); }); }); }, // 保存视频到相册(通用方法) saveVideoToAlbum(filePath, item) { return new Promise((resolve, reject) => { uni.saveVideoToPhotosAlbum({ filePath, success: resolve, fail: (err) => { console.error('保存到相册失败:', err); // 尝试保存到下载目录(Android专用) if (uni.getSystemInfoSync().platform === 'android') { this.saveToDownloadsAndroid(filePath, `video_${Date.now()}.mp4`) .then(resolve) .catch(reject); } else { reject(new Error('保存失败,请检查存储权限')); } } }); }); }, // Android专用:保存到下载目录(适配Android 10+) saveToDownloadsAndroid(filePath, fileName) { return new Promise((resolve, reject) => { if (plus.os.name.toLowerCase() !== 'android') { return reject(new Error('仅Android支持此方法')); } try { const dtask = uni.downloadFile({ url: filePath, // 这里需要重新下载以确保获取临时文件 success: (res) => { if (res.statusCode !== 200) { return reject(new Error(`下载失败,状态码:${res.statusCode}`)); } // 使用MediaStore插入到下载目录 const Context = plus.android.importClass("android.content.Context"); const ContentResolver = plus.android.importClass("android.content.ContentResolver"); const ContentValues = plus.android.importClass("android.content.ContentValues"); const Environment = plus.android.importClass("android.os.Environment"); const MediaStore = plus.android.importClass("android.provider.MediaStore"); const resolver = plus.android.runtimeMainActivity().getContentResolver(); const values = new ContentValues(); values.put(MediaStore.Video.Media.DISPLAY_NAME, fileName); values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4"); values.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + "/"); const uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values); if (uri) { const os = resolver.openOutputStream(uri); const file = new plus.android.bridges.File(res.tempFilePath); const input = new plus.android.bridges.FileInputStream(file); const buffer = new ArrayBuffer(1024); let length; while ((length = input.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); os.close(); input.close(); resolve(); } else { reject(new Error('无法创建媒体存储条目')); } }, fail: (err) => reject(new Error(`重新下载失败: ${err.errMsg}`)) }); dtask.onProgressUpdate(() => {}); // 静默处理进度 } catch (error) { reject(error); } }); }, // 文档下载方法(优化版) downloadFile(item) { try { let fileUrl = item.documentUrl; // 处理URL格式 if (!fileUrl.startsWith('http')) { fileUrl = this.processVideoUrl(fileUrl); // 复用视频URL处理逻辑 } const fileName = item.documentName || fileUrl.split('/').pop() || '未命名文件'; uni.showLoading({ title: '准备下载...', mask: true }); // 先检查文件是否存在 this.checkUrlAvailable(fileUrl).then(async (exists) => { if (!exists) { throw new Error('文件资源不存在(404)'); } // 开始下载 uni.downloadFile({ url: fileUrl, success: (downloadResult) => { uni.hideLoading(); if (downloadResult.statusCode === 200) { // 尝试直接打开 uni.openDocument({ filePath: downloadResult.tempFilePath, fileType: this.getFileType(fileName), showMenu: true, success: () => { console.log('文档打开成功'); }, fail: (err) => { console.error('打开文档失败:', err); // 打开失败则保存到下载目录 this.saveFileToDownloads(downloadResult.tempFilePath, fileName) .then(() => { uni.showToast({ title: '文件已保存到下载目录', icon: 'success' }); }) .catch(() => { uni.showToast({ title: '保存失败,请重试', icon: 'none' }); }); } }); } else { uni.hideLoading(); uni.showToast({ title: `下载失败(状态码:${downloadResult.statusCode})`, icon: 'none' }); } }, fail: (err) => { uni.hideLoading(); console.error('下载失败:', err); uni.showToast({ title: `下载失败:${err.errMsg}`, icon: 'none' }); } }); }).catch((error) => { uni.hideLoading(); uni.showToast({ title: error.message, icon: 'none' }); }); } catch (error) { uni.showToast({ title: `下载异常:${error.message}`, icon: 'none' }); } }, // 保存文件到下载目录(通用方法) saveFileToDownloads(tempPath, fileName) { return new Promise((resolve, reject) => { if (uni.getSystemInfoSync().platform === 'android') { // Android使用plus API保存 const Context = plus.android.importClass("android.content.Context"); const ContentResolver = plus.android.importClass("android.content.ContentResolver"); const ContentValues = plus.android.importClass("android.content.ContentValues"); const Environment = plus.android.importClass("android.os.Environment"); const resolver = plus.android.runtimeMainActivity().getContentResolver(); const values = new ContentValues(); values.put(ContentResolver.COLUMN_DISPLAY_NAME, fileName); values.put(ContentResolver.COLUMN_MIME_TYPE, "*/*"); values.put(Environment.DIRECTORY_DOWNLOADS, Environment.DIRECTORY_DOWNLOADS); const uri = resolver.insert(ContentResolver.URI_CONTENT_DOCUMENTS_URI, values); if (uri) { const os = resolver.openOutputStream(uri); const file = new plus.android.bridges.File(tempPath); const input = new plus.android.bridges.FileInputStream(file); const buffer = new ArrayBuffer(1024); let length; while ((length = input.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); os.close(); input.close(); resolve(); } else { reject(new Error('无法创建下载条目')); } } else { // iOS使用系统API保存 uni.saveFile({ tempFilePath, success: (res) => { uni.showToast({ title: '文件已保存', icon: 'success' }); resolve(); }, fail: reject }); } }); }, // 获取文件类型 getFileType(fileName) { const ext = fileName.split('.').pop().toLowerCase(); switch(ext) { case 'pdf': return 'pdf'; case 'doc': case 'docx': return 'doc'; case 'xls': case 'xlsx': return 'xls'; case 'ppt': case 'pptx': return 'ppt'; case 'zip': case 'rar': return 'zip'; case 'jpg': case 'jpeg': case 'png': case 'gif': return 'image'; default: return 'unknown'; } }, // 格式化富文本(增强版) formatRichText(html) { if (!html) return ''; let content = html // 修复图片样式 .replace(/<img[^>]*>/gi, (match) => { return match .replace(/(style|width|height)="[^"]*"/gi, '') .replace(/<img/, '<img style="max-width:100% !important;height:auto !important;display:block;margin:10px auto;border-radius:4px;"'); }) // 修复视频/iframe样式 .replace(/<iframe[^>]*>/gi, '<iframe style="width:100%;height:200px;margin:10px 0;border:none;border-radius:4px;" allowfullscreen>') // 修复段落样式 .replace(/<p[^>]*>/gi, '<p style="margin:10px 0;line-height:1.6;text-align:justify;font-size:16px;color:#333;">'); return content; }, // 获取产品详情 getProductCurrent() { request('/labdev/product/list0', this.productDeivece, res => { if (res.data.code !== 200) { uni.showToast({ mask: true, icon: 'none', title: '查询失败:' + (res.data.msg || '未知错误') }); return; } this.productForm = res.data.rows; if (!this.productForm || this.productForm.length === 0) { uni.showToast({ title: '未找到产品信息', icon: 'none' }); return; } // 处理文档列表 const docStr = this.productForm[0].document; let documentList = []; if (docStr) { documentList = docStr.split(',').map(item => { if (!item) return null; const type = item.split('.').pop().toLowerCase(); return { documentType: type, documentUrl: this.processVideoUrl(item), // 复用URL处理逻辑 documentName: item.split('/').pop() || '未命名文档' }; }).filter(item => item !== null); // 过滤空值 } this.documentList = documentList; // 处理视频列表 const videoUrl = this.productForm[0].video; if (videoUrl) { this.videoList = [{ videoUrl: this.processVideoUrl(videoUrl), documentName: videoUrl.split('/').pop() || '未命名视频', error: null }]; } else { this.videoList = []; } // 处理轮播图 this.getPicture(); // 处理富文本内容 this.introduce = this.formatRichText(this.productForm[0].introduce || ''); this.parameter = this.formatRichText(this.productForm[0].parameter || ''); }, err => { uni.showToast({ mask: true, icon: 'none', title: '查询信息获取失败:' + (err.message || '未知错误') }); }, 'GET' ) }, // 其他原有方法(略作调整) async saveVideoToAlbumAndroid10Plus(videoUrl, item) { try { const fileName = item.documentName || videoUrl.split('/').pop(); // 使用plus API处理高版本Android if (uni.getSystemInfoSync().platform === 'android') { const dtask = uni.downloadFile({ url: videoUrl, success: (res) => { if (res.statusCode === 200) { // 使用MediaStore插入视频 const Context = plus.android.importClass("android.content.Context"); const ContentResolver = plus.android.importClass("android.content.ContentResolver"); const ContentValues = plus.android.importClass("android.content.ContentValues"); const Environment = plus.android.importClass("android.os.Environment"); const MediaStore = plus.android.importClass("android.provider.MediaStore"); const resolver = plus.android.runtimeMainActivity().getContentResolver(); const values = new ContentValues(); values.put(MediaStore.Video.Media.DISPLAY_NAME, fileName); values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4"); values.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_MOVIES + "/Download/"); const uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values); if (uri) { const os = resolver.openOutputStream(uri); const file = new plus.android.bridges.File(res.tempFilePath); const input = new plus.android.bridges.FileInputStream(file); const buffer = new ArrayBuffer(1024); let length; while ((length = input.read(buffer)) > 0) { os.write(buffer, 0, length); } os.flush(); os.close(); input.close(); uni.showToast({ title: '视频已保存到相册', icon: 'success' }); } else { throw new Error('无法创建媒体存储条目'); } } else { throw new Error(`下载失败,状态码: ${res.statusCode}`); } }, fail: (err) => { throw new Error(`下载失败: ${err.errMsg}`); } }); // 监听下载进度 dtask.onProgressUpdate((res) => { uni.showLoading({ title: `下载中 ${res.progress}%`, mask: true }); }); } else { throw new Error('当前平台不支持此方法'); } } catch (error) { console.error('保存视频失败:', error); throw error; } }, // 其他工具方法(保持原有逻辑) async checkStoragePermission() { try { if (uni.getSystemInfoSync().platform === 'android') { const result = await uni.getSetting(); if (!result.authSetting['scope.writePhotosAlbum']) { const res = await uni.authorize({ scope: 'scope.writePhotosAlbum' }); return !!res; } return true; } return true; } catch (error) { console.error('权限检查失败:', error); return false; } }, getErrorMessage(error) { if (error.message.includes('404')) return '资源不存在'; if (error.message.includes('timeout')) return '下载超时,请重试'; if (error.message.includes('permission')) return '无存储权限,请在设置中开启'; if (error.message.includes('HEAD')) return '无法连接到服务器'; return '下载失败,请稍后重试'; }, tabsChange(index) { this.tabCurrent = index.index; }, goBack() { uni.removeStorageSync("productDeivce"); uni.navigateBack({ delta: 1 }); }, getPicture() { let matches = this.productForm[0]?.picture?.match(/data:image\/[^;]+;base64,[^,]+/g) || []; this.list2 = matches; } } } </script> <style scoped> page { background-size: cover; background-repeat: no-repeat; background-attachment: fixed; position: fixed; left: 0; top: 0; right: 0; bottom: 0; } .rich-text-container { width: 100%; padding: 0 10px; box-sizing: border-box; overflow: hidden; word-wrap: break-word; } .rich-text-container img { max-width: 100% !important; height: auto !important; display: block; margin: 10px auto; border-radius: 4px; } .rich-text-container p { margin: 10px 0; line-height: 1.6; text-align: justify; font-size: 16px; color: #333; } .rich-text-container iframe { width: 100%; height: 200px; margin: 10px 0; border-radius: 4px; border: none; } .rich-text-container table { width: 100% !important; border-collapse: collapse; margin: 10px 0; } .rich-text-container table, .rich-text-container th, .rich-text-container td { border: 1px solid #ddd; padding: 8px; } .rich-text-container th { background-color: #f2f2f2; } </style>这里的各种文件和视频的下载有问题,在手机端无法下载,需要在手机端可以下载到文件管理里面
最新发布
07-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值