zip文件怎么安装到手机

您所在的位置:网站首页 手机软件解压后如何安装 zip文件怎么安装到手机

zip文件怎么安装到手机

#zip文件怎么安装到手机| 来源: 网络整理| 查看: 265

效果图:

 

 

 

 

关于Android文件存储路径:

参考:彻底搞懂Android文件存储---内部存储,外部存储以及各种存储路径解惑_ 雨季莫忧离的博客-CSDN博客

1、Environment.getDataDirectory() = /data 这个方法是获取内部存储的根路径 2、getFilesDir().getAbsolutePath() = /data/user/0/packname/files 这个方法是获取某个应用在内部存储中的files路径 3、getCacheDir().getAbsolutePath() = /data/user/0/packname/cache 这个方法是获取某个应用在内部存储中的cache路径 4、getDir(“myFile”, MODE_PRIVATE).getAbsolutePath() = /data/user/0/packname/app_myFile 这个方法是获取某个应用在内部存储中的自定义路径 方法2,3,4的路径中都带有包名,说明他们是属于某个应用 ………………………………………………………………………………………… 5、Environment.getExternalStorageDirectory().getAbsolutePath() = /storage/emulated/0 这个方法是获取外部存储的根路径 6、Environment.getExternalStoragePublicDirectory(“”).getAbsolutePath() = /storage/emulated/0 这个方法是获取外部存储的根路径 7、getExternalFilesDir(“”).getAbsolutePath() = /storage/emulated/0/Android/data/packname/files 这个方法是获取某个应用在外部存储中的files路径 8、getExternalCacheDir().getAbsolutePath() = /storage/emulated/0/Android/data/packname/cache 这个方法是获取某个应用在外部存储中的cache路径

先安利一个GitHub的Android工具类代码集合:AndroidUtilCode/README-CN.md at master · Blankj/AndroidUtilCode · GitHub

感兴趣的可以去看看,个人感觉很好用,已经star了~

压缩文件成zip的工具类就是在上面扒下来的:

建议直接用我这个类,后面加了几个获取所有文件名的方法。

ZipUtils.class: package cnwy.xda.threedpolygontest.utils; import android.util.Log; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; /** * * author: Blankj * blog : http://blankj.com * time : 2016/08/27 * desc : utils about zip * */ public final class ZipUtils { private static final int BUFFER_LEN = 8192; private ZipUtils() { throw new UnsupportedOperationException("u can't instantiate me..."); } /** * Zip the files. * * @param srcFiles The source of files. * @param zipFilePath The path of ZIP file. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFiles(final Collection srcFiles, final String zipFilePath) throws IOException { return zipFiles(srcFiles, zipFilePath, null); } /** * Zip the files. * * @param srcFilePaths The paths of source files. * @param zipFilePath The path of ZIP file. * @param comment The comment. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFiles(final Collection srcFilePaths, final String zipFilePath, final String comment) throws IOException { if (srcFilePaths == null || zipFilePath == null) return false; ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(zipFilePath)); for (String srcFile : srcFilePaths) { if (!zipFile(getFileByPath(srcFile), "", zos, comment)) return false; } return true; } finally { if (zos != null) { zos.finish(); zos.close(); } } } /** * Zip the files. * * @param srcFiles The source of files. * @param zipFile The ZIP file. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFiles(final Collection srcFiles, final File zipFile) throws IOException { return zipFiles(srcFiles, zipFile, null); } /** * Zip the files. * * @param srcFiles The source of files. * @param zipFile The ZIP file. * @param comment The comment. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFiles(final Collection srcFiles, final File zipFile, final String comment) throws IOException { if (srcFiles == null || zipFile == null) return false; ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(zipFile)); for (File srcFile : srcFiles) { if (!zipFile(srcFile, "", zos, comment)) return false; } return true; } finally { if (zos != null) { zos.finish(); zos.close(); } } } /** * Zip the file. * * @param srcFilePath The path of source file. * @param zipFilePath The path of ZIP file. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFile(final String srcFilePath, final String zipFilePath) throws IOException { return zipFile(getFileByPath(srcFilePath), getFileByPath(zipFilePath), null); } /** * Zip the file. * * @param srcFilePath The path of source file. * @param zipFilePath The path of ZIP file. * @param comment The comment. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFile(final String srcFilePath, final String zipFilePath, final String comment) throws IOException { return zipFile(getFileByPath(srcFilePath), getFileByPath(zipFilePath), comment); } /** * Zip the file. * * @param srcFile The source of file. * @param zipFile The ZIP file. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFile(final File srcFile, final File zipFile) throws IOException { return zipFile(srcFile, zipFile, null); } /** * Zip the file. * * @param srcFile The source of file. * @param zipFile The ZIP file. * @param comment The comment. * @return {@code true}: success{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFile(final File srcFile, final File zipFile, final String comment) throws IOException { if (srcFile == null || zipFile == null) return false; ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(zipFile)); return zipFile(srcFile, "", zos, comment); } finally { if (zos != null) { zos.close(); } } } private static boolean zipFile(final File srcFile, String rootPath, final ZipOutputStream zos, final String comment) throws IOException { rootPath = rootPath + (isSpace(rootPath) ? "" : File.separator) + srcFile.getName(); if (srcFile.isDirectory()) { File[] fileList = srcFile.listFiles(); if (fileList == null || fileList.length entries = zip.entries(); while (entries.hasMoreElements()) { String entryName = ((ZipEntry) entries.nextElement()).getName().replace("\\", "/");; if (entryName.contains("../")) { Log.e("ZipUtils", "entryName: " + entryName + " is dangerous!"); paths.add(entryName); } else { paths.add(entryName); } } zip.close(); return paths; } /** * Return the files' comment in ZIP file. * * @param zipFilePath The path of ZIP file. * @return the files' comment in ZIP file * @throws IOException if an I/O error has occurred */ public static List getComments(final String zipFilePath) throws IOException { return getComments(getFileByPath(zipFilePath)); } /** * Return the files' comment in ZIP file. * * @param zipFile The ZIP file. * @return the files' comment in ZIP file * @throws IOException if an I/O error has occurred */ public static List getComments(final File zipFile) throws IOException { if (zipFile == null) return null; List comments = new ArrayList(); ZipFile zip = new ZipFile(zipFile); Enumeration entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); comments.add(entry.getComment()); } zip.close(); return comments; } private static boolean createOrExistsDir(final File file) { return file != null && (file.exists() ? file.isDirectory() : file.mkdirs()); } private static boolean createOrExistsFile(final File file) { if (file == null) return false; if (file.exists()) return file.isFile(); if (!createOrExistsDir(file.getParentFile())) return false; try { return file.createNewFile(); } catch (IOException e) { e.printStackTrace(); return false; } } private static File getFileByPath(final String filePath) { return isSpace(filePath) ? null : new File(filePath); } private static boolean isSpace(final String s) { if (s == null) return true; for (int i = 0, len = s.length(); i < len; ++i) { if (!Character.isWhitespace(s.charAt(i))) { return false; } } return true; } public static List getFilesAllName(String path) { File file=new File(path); File[] files=file.listFiles(); if (files == null){Log.e("error","空目录");return null;} List s = new ArrayList(); for(int i =0;i= Build.VERSION_CODES.N && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { uri = FileProvider.getUriForFile(mContext, mContext.getApplicationContext().getPackageName() + ".fileprovider", picFile); } else { uri = Uri.fromFile(picFile); } intent.putExtra(Intent.EXTRA_STREAM, uri); } catch (Exception e) { e.printStackTrace(); } } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // if (getVersionCode(mContext, PACKAGE_WECHAT) > VERSION_CODE_FOR_WEI_XIN_VER7) { // 微信7.0及以上版本 intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uri); // } mContext.startActivity(Intent.createChooser(intent, "分享文件")); } else { Toast.makeText(mContext, "您需要安装微信客户端", Toast.LENGTH_LONG).show(); } } // 建立一个文件类型与文件后缀名的匹配表 private static final String[][] MATCH_ARRAY = { //{后缀名, 文件类型} {".3gp", "video/3gpp"}, {".apk", "application/vnd.android.package-archive"}, {".asf", "video/x-ms-asf"}, {".avi", "video/x-msvideo"}, {".bin", "application/octet-stream"}, {".bmp", "image/bmp"}, {".c", "text/plain"}, {".class", "application/octet-stream"}, {".conf", "text/plain"}, {".cpp", "text/plain"}, {".doc", "application/msword"}, {".exe", "application/octet-stream"}, {".gif", "image/gif"}, {".gtar", "application/x-gtar"}, {".gz", "application/x-gzip"}, {".h", "text/plain"}, {".htm", "text/html"}, {".html", "text/html"}, {".jar", "application/java-archive"}, {".java", "text/plain"}, {".jpeg", "image/jpeg"}, {".jpg", "image/jpeg"}, {".js", "application/x-javascript"}, {".log", "text/plain"}, {".m3u", "audio/x-mpegurl"}, {".m4a", "audio/mp4a-latm"}, {".m4b", "audio/mp4a-latm"}, {".m4p", "audio/mp4a-latm"}, {".m4u", "video/vnd.mpegurl"}, {".m4v", "video/x-m4v"}, {".mov", "video/quicktime"}, {".mp2", "audio/x-mpeg"}, {".mp3", "audio/x-mpeg"}, {".mp4", "video/mp4"}, {".mpc", "application/vnd.mpohun.certificate"}, {".mpe", "video/mpeg"}, {".mpeg", "video/mpeg"}, {".mpg", "video/mpeg"}, {".mpg4", "video/mp4"}, {".mpga", "audio/mpeg"}, {".msg", "application/vnd.ms-outlook"}, {".ogg", "audio/ogg"}, {".pdf", "application/pdf"}, {".png", "image/png"}, {".pps", "application/vnd.ms-powerpoint"}, {".ppt", "application/vnd.ms-powerpoint"}, {".prop", "text/plain"}, {".rar", "application/x-rar-compressed"}, {".rc", "text/plain"}, {".rmvb", "audio/x-pn-realaudio"}, {".rtf", "application/rtf"}, {".sh", "text/plain"}, {".tar", "application/x-tar"}, {".tgz", "application/x-compressed"}, {".txt", "text/plain"}, {".wav", "audio/x-wav"}, {".wma", "audio/x-ms-wma"}, {".wmv", "audio/x-ms-wmv"}, {".wps", "application/vnd.ms-works"}, {".xml", "text/plain"}, {".z", "application/x-compress"}, {".zip", "application/zip"}, {"", "*/*"} }; /** * 压缩文件和文件夹 * * @param srcFileString 要压缩的文件或文件夹 * @param zipFileString 压缩完成的Zip路径 * @throws Exception */ public static void ZipFolder(String srcFileString, String zipFileString) throws Exception { //创建ZIP ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileString)); //创建文件 File file = new File(srcFileString); //压缩 ZipFiles(file.getParent()+ File.separator, file.getName(), outZip); //完成和关闭 outZip.finish(); outZip.close(); } /** * 压缩文件 * * @param folderString * @param fileString * @param zipOutputSteam * @throws Exception */ private static void ZipFiles(String folderString, String fileString, ZipOutputStream zipOutputSteam) throws Exception { if (zipOutputSteam == null) return; File file = new File(folderString + fileString); if (file.isFile()) { String path = folderString.replace(Environment.getExternalStoragePublicDirectory("/imagefiles").getPath()+"/",""); ZipEntry zipEntry = new ZipEntry(path+fileString); FileInputStream inputStream = new FileInputStream(file); zipOutputSteam.putNextEntry(zipEntry); int len; byte[] buffer = new byte[4096]; while ((len = inputStream.read(buffer)) != -1) { zipOutputSteam.write(buffer, 0, len); } zipOutputSteam.closeEntry(); } else { //文件夹 String fileList[] = file.list(); //没有子文件和压缩 if (fileList.length Build.VERSION_CODES.Q) { // shareWechatFriend(context, file); // return; // } // //构建发送文件体 // WXFileObject fileObject = new WXFileObject(); // /*经实测,不给fileObject设置fileData,也是可以分享文件得,且大小默认10M以内 // 反而是设置了fileData属性的话,分享文件大小不能大于500kb,且在Android11以上无法分享,坑啊, // 所以,在Android11上需要走FileProvider文件分享的方式*/ // //设置需要发送的文件byte[] // //byte[] fileBytes = readFile(file); // //fileObject.setFileData(fileBytes); // fileObject.setFilePath(file.getAbsolutePath()); // fileObject.setContentLengthLimit(1024 * 1024 * 10); // //使用媒体消息分享 // WXMediaMessage msg = new WXMediaMessage(fileObject); // //这个title有讲究,最好设置为带后缀的文件名,否则可能分享到微信后无法读取 // msg.title = file.getName(); // //设置显示的预览图 需小于32KB // if (thumbId


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3