- // Convert the URL to a URI.
- Uri uri = Uri.parse(url);
-
- // Get the last path segment.
- String lastPathSegment = uri.getLastPathSegment();
-
- // Use a default file name if the last path segment is null.
- if (lastPathSegment == null) {
- lastPathSegment = getString(R.string.file);
- }
-
- // Use the last path segment as the file name.
- fileName = lastPathSegment;