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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user