gpt4 book ai didi

java - 下载 apk,没有这样的文件或目录错误..

转载 作者:行者123 更新时间:2023-12-02 12:28:00 25 4
gpt4 key购买 nike

我正在创建一个应用程序,它从网络服务器下载 apk 文件然后安装它,但我遇到了问题,当我单击下载时,进度条会进行比较,但它不会改变,并且在 Android 中监视器对此进行了比较: Error displayed

我正在使用 android 7.1.1 的 avd,我将尝试使用 marshmallow。这是代码:

    try {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
String sdPath = Environment.getExternalStorageDirectory() + "/";

mSavePath = sdPath + "updateDownload";
File dir = new File(mSavePath);

if (!dir.exists())
if (dir.mkdir())
Log.d(TAG, "mkdir success");
else
Log.d(TAG, "mkdir failed!");

HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection();
conn.connect();

InputStream is = conn.getInputStream();

int length = conn.getContentLength();

File apkFile = new File(mSavePath, version_name);

FileOutputStream fos = new FileOutputStream(apkFile);

int count = 0;
byte[] buffer = new byte[1024];
while (!isCancel) {
int numread = is.read(buffer);
count += numread;
mProgress = (int) ((float) (count / length) * 100);

mUpdateProgressHandler.sendEmptyMessage(DOWNLOADING);
if (numread < 0) {
mUpdateProgressHandler.sendEmptyMessage(DOWNDLOAD_FINISHED);
break;
}
fos.write(buffer, 0, numread);

}
fos.close();
is.close();

} else {
Log.d(TAG, " Media not mounted");
}


} catch (Exception e) {
e.printStackTrace();
}

最佳答案

Android 6.0之后需要运行时权限引用https://developer.android.com/training/permissions/requesting.html

关于java - 下载 apk,没有这样的文件或目录错误..,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45413361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com