Alexander Shutau
Alexander Shutau

Reputation: 2810

Prevent extension prefix (1) when saving a file on Android

I'm using the following code to let users save a file on Android:

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, fileName);
startActivityForResult(intent, 2);

where fileName is something like "Drawing 1.ink". The problem is when a file with the same name already exists, a user is suggested to save a new file under "Drawing 1.ink (1)" name. People often save files with "ink (1)" extension.

How to prevent this and make a default suggested file name like "Drawing 1 (1).ink"? Or forcing a suggested name without "(1)"?

Upvotes: 3

Views: 537

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006944

How to prevent this

You can't.

Or forcing a suggested name without "(1)"?

You can't.

I want to have control over file extension

You can't.

This is a system-supplied UI, not significantly different from platform-supplied "file save-as" dialogs that we have used for decades. You're welcome to file feature requests to improve the available options here, though such changes would only take effect with Android 12 or some other future version.

Upvotes: 1

Related Questions