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.
diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java
index eb863ef..6bf09b5 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 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;
+ }
}
}