diff options
| -rw-r--r-- | core/java/android/provider/Downloads.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java index eb863ef77f46..6bf09b592528 100644 --- a/core/java/android/provider/Downloads.java +++ b/core/java/android/provider/Downloads.java @@ -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; + } } } |