Add download file to folder with the name of the application

This commit is contained in:
Erwan Croze 2018-08-01 15:42:17 +02:00
parent 530ede085b
commit 58ed1e954c
2 changed files with 8 additions and 3 deletions

View file

@ -357,10 +357,13 @@ public class ChatEventsAdapter extends ListSelectionAdapter {
if (mContext.getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
v.setEnabled(false);
String filename = message.getFileTransferInformation().getName();
File file = new File(Environment.getExternalStorageDirectory(), filename);
String directory_path = Environment.getExternalStorageDirectory() + "/" + mContext.getString(R.string.app_name);
File file = new File(Environment.getExternalStorageDirectory(), mContext.getString(R.string.app_name));
file.mkdirs();
file = new File(directory_path, filename);
int prefix = 1;
while (file.exists()) {
file = new File(Environment.getExternalStorageDirectory(), prefix + "_" + filename);
file = new File(directory_path, prefix + "_" + filename);
Log.w("File with that name already exists, renamed to " + prefix + "_" + filename);
prefix += 1;
}

View file

@ -595,7 +595,9 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
private void pickFile() {
List<Intent> cameraIntents = new ArrayList<>();
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())+".jpeg"));
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
file.mkdirs();
file = new File(Environment.getExternalStorageDirectory() + "/" + getString(R.string.app_name), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())+".jpeg"));
mImageToUploadUri = Uri.fromFile(file);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageToUploadUri);
cameraIntents.add(captureIntent);