简体   繁体   English

可在Android中下载的APK文件位于哪里?

[英]Where is located the APK file for download in android?

I'm currently developing an app that need to check if there is a new version available. 我目前正在开发需要检查是否有可用新版本的应用程序。 I found how to download the apk and install it. 我找到了如何下载并安装APK。 But i cant figure out how to get the APK URL. 但我不知道如何获取APK URL。 I'm using the testing (alpha) environment, so my app is not published yet, where can i get the APK URL. 我正在使用测试(alpha)环境,因此我的应用尚未发布,我可以在哪里获得APK URL。 Here's the code for download: 这是下载代码:

            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();
        }

How can i get the APK URL? 如何获取APK URL?

you have to create it yourself. 您必须自己创建它。 create folder and name a file to it. 创建文件夹并为其命名文件。 as you are doing in the code. 就像您在代码中所做的一样。 like 喜欢

  String PATH = Environment.getExternalStorageDirectory() + "/download/";
            File file = new File(PATH);
            file.mkdirs();
            File outputFile = new File(file, "app.apk");

to create your own one do this. 创建自己的一个做到这一点。

Add this permission in Manifest, 在清单中添加此权限,

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

and to create folder with name of your file 并使用文件名创建文件夹

    File folder = new File(context.getCacheDir().getPath() + "/files/myFolder");
folder.mkdirs();

File f= new File(folder, "app.apk");
if (!folder .exists()){
    folder.create();
}

where you can put your apk 您可以在其中放置APK

If you are using Alpha (testing) environment. 如果您正在使用Alpha(测试)环境。 This is the Url: 这是网址:

https://play.google.com/apps/testing/com.yourdomain.package

But, your APK will not be available to public, it is ONLY for activated testers in the alpha section. 但是,您的APK将无法公开使用,只有Alpha部分中的激活测试人员可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM