0

我们如何从无根设备访问 APK 文件并将其复制到外部存储?

任何指导都会很棒,

谢谢

4

1 回答 1

0

使用此功能将 APK 从源包路径复制到您的 sdcard(无需 root 访问权限)

public static boolean copyFile(String srcFilePath, String destFilePath)
     {
     boolean success = false;

     if(srcFilePath!=null && destFilePath!=null)
     {
     srcFilePath = srcFilePath.trim();
     destFilePath = destFilePath.trim();

     if(!srcFilePath.equals("") && !destFilePath.equals("") && !srcFilePath.equals(destFilePath))
     {
     File srcFile = new File(srcFilePath);

     if(srcFile.exists() && srcFile.isFile())
     {
     try
     {
     File destFile = new File(destFilePath);
     InputStream in = new FileInputStream(srcFile);
     OutputStream out = new FileOutputStream(destFile);

    // Transfer bytes from in to out
     byte[] buf = new byte[1024];
     int len;
     while ((len = in.read(buf)) > 0)
     {
     out.write(buf, 0, len);
     }

     in.close();
     out.close();
     success = true;
     }
     catch (Exception e)
     {
     e.printStackTrace();
     }
     }
     }
     }
     return success;
     }
于 2013-10-14T12:25:41.617 回答