Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL url = new URL(urlToDownload);
- URLConnection connection = url.openConnection();
- connection.connect();
- // this will be useful so that you can show a typical 0-100% progress bar
- int fileLength = connection.getContentLength();
- // download the file
- InputStream input = new BufferedInputStream(connection.getInputStream());
- OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk");
- byte data[] = new byte[1024];
- long total = 0;
- int count;
- while ((count = input.read(data)) != -1) {
- total += count;
- // publishing the progress....
- Bundle resultData = new Bundle();
- resultData.putInt("progress" ,(int) (total * 100 / fileLength));
- receiver.send(UPDATE_PROGRESS, resultData);
- output.write(data, 0, count);
- }
- output.flush();
- output.close();
- input.close();
- private void srcDirs(String path)
- {
- File directory = new File(path);
- File [] DirList = directory.listFiles();
- AssetManager assetManager = this.getAssets();
- InputStream in = null;
- OutputStream out = null;
- for(File dirname: DirList)
- {
- String fullPath = extStorageDirectory + "/Pictures/" + dirname.getName(); // destination
- if(dirname.isFile())
- {
- try{
- in = assetManager.open(path);
- String newFileName = fullPath + "/" + dirname ;
- out = new FileOutputStream(newFileName);
- byte[] buffer = new byte[1024];
- int read;
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
- }
- in.close();
- in = null;
- out.flush();
- out.close();
- out = null;
- }
- catch (Exception e) {
- Log.e("tag", e.getMessage());
- }
- }
- else if(dirname.isDirectory())
- {
- File desdir = new File(fullPath);
- if(!desdir.exists())
- {
- desdir.mkdirs();
- }
- }
- }
- <uses-permission
- android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.READ_PHONE_STATE" />
- URL url = new URL("10.../.././CPI"); // hypothetically
- URLConnection connection = url.openConnection();
Add Comment
Please, Sign In to add comment