@Override public void run() { try { InputStream inputStream = null; if (position == -1) inputStream = SApp.getContext().getAssets().open("skins/" + skins.get(id).skin); else inputStream = SApp.getContext().getAssets().open("collections/" + collections.get(id).name + "/" + collections.get(id).skins.get(position).skin); File dest = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), skins.get(id).skin); FileOutputStream outputStream = new FileOutputStream(dest); MediaScannerConnection.scanFile(this, new String[]{dest.getPath()}, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { // now visible in gallery } }); byte[] buf = new byte[256]; int i = 0; do { i = inputStream.read(buf); if (i == -1) break; outputStream.write(buf, 0, i); } while (i != -1); inputStream.close(); outputStream.flush(); outputStream.close(); Intent intent = new Intent(); intent.setAction(ACTION_COPY_COMPLETE); SApp.getContext().sendBroadcast(intent); } catch (IOException e) { e.printStackTrace(); } } } 

    0