Eli
Eli

Reputation: 626

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. But i cant figure out how to get the APK URL. I'm using the testing (alpha) environment, so my app is not published yet, where can i get the 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?

Upvotes: 0

Views: 2399

Answers (2)

Pramod mishra
Pramod mishra

Reputation: 625

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

Upvotes: 2

Umit Kaya
Umit Kaya

Reputation: 5961

If you are using Alpha (testing) environment. 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.

Upvotes: 0

Related Questions