在android中下载的APK文件在哪里?
我目前正在开发一个应用程序,需要检查是否有新版本可用。 我找到了如何下载apk并安装它。 但我不知道如何获取APK URL。 我正在使用测试(alpha)环境,所以我的应用程序还没有发布,在哪里可以获得APK URL。 以下是下载代码:在android中下载的APK文件在哪里?,android,android-studio,google-play,Android,Android Studio,Google Play,我目前正在开发一个应用程序,需要检查是否有新版本可用。 我找到了如何下载apk并安装它。 但我不知道如何获取APK URL。 我正在使用测试(alpha)环境,所以我的应用程序还没有发布,在哪里可以获得APK URL。 以下是下载代码: try { URL url = new URL(apkurl); HttpURLConnection c = (HttpURLConnection) url.openConnection()
try {
URL url = new URL(apkurl);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();//till here, it works fine - .apk is download to my sdcard in download file
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Update error!", Toast.LENGTH_LONG).show();
}
如何获取APK URL?如果您使用的是Alpha(测试)环境。这是Url:
https://play.google.com/apps/testing/com.yourdomain.package
但是,您的APK将不向公众提供,它仅适用于alpha部分中激活的测试人员。如果您使用的是alpha(测试)环境。这是Url:
https://play.google.com/apps/testing/com.yourdomain.package
但是,您的APK将不会向公众提供,它仅适用于alpha部分中激活的测试人员。您必须自己创建它。创建文件夹并为其命名一个文件。正如您在代码中所做的那样。像
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
要创建自己的,请执行此操作
在清单中添加此权限,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
你可以把apk放在哪里,你必须自己创建它。创建文件夹并为其命名一个文件。正如您在代码中所做的那样。像
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
要创建自己的,请执行此操作
在清单中添加此权限,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
您可以将apk放在哪里您正在将apk下载到
环境中。getExternalStorageDirectory()+“/download/”代码>目录命名app.apk。在下载时,您也可以使用`intent.setDataAndType(Uri.fromFile(新文件(Environment.getExternalStorageDirectory()+“/download/”+“app.apk”),“application/vnd.android.package archive”);`那么,您得到的错误是什么?如何知道应该将文件下载到哪个文件夹?您正在将apk下载到Environment.getExternalStorageDirectory()+“/download/”代码>目录命名app.apk。在下载时,您也可以使用`intent.setDataAndType(Uri.fromFile(新文件(Environment.getExternalStorageDirectory()+“/download/”+“app.apk”),“application/vnd.android.package archive”);`那么,您遇到了什么错误?我如何知道应该将文件下载到哪个文件夹?好的,谢谢,我如何知道将文件下载到哪个文件夹?好的,谢谢,我如何知道将文件下载到哪个文件夹?