Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe79ef44 authored by Leon Scroggins's avatar Leon Scroggins
Browse files

Create a common method for updating the title of a download from the filename.

This method will be used by the DownloadProvider and the BrowserDownloadPage.
parent dcf19a8d
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@
package android.provider;

import android.net.Uri;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;

import java.io.File;

/**
 * The Download Manager
@@ -1065,5 +1070,27 @@ public final class Downloads {
         */
        public static final int VISIBILITY_HIDDEN = 2;

        /**
         * Using a file name, create a title for a download.  Then store it in
         * the database and return it.
         *
         * @param context Context for reaching the {@link ContentResolver} so
         *      the database can be updated with the new title.
         * @param filename Full path to the file.  Used to generate a title.
         * @param id Id of the download, so the new title can be stored in the
         *      database
         * @return String Newly created title.
         * @hide
         */
        public static String createTitleFromFilename(Context context,
                String filename, long id) {
            if (filename == null) return null;
            String title = new File(filename).getName();
            ContentValues values = new ContentValues();
            values.put(COLUMN_TITLE, title);
            context.getContentResolver().update(ContentUris.withAppendedId(
                    CONTENT_URI, id), values, null, null);
            return title;
        }
    }
}