Android(SpreadTurm)无T卡下载文件导致无法释放手机内存
2012-11-23 10:31
573 查看
【原因】在删除下载记录时没有删除源文件,同时因用户有没有权限查看路径:/data/internal_memory下的文件
【修改】删除记录时一起把源文件也删除
idh.code\packages\providers\DownloadProvider\ui\src\com\android\providers\downloads\ui\DownloadList.java
private void deleteDownload(long downloadId) {
if (moveToDownload(downloadId)) {
int status = mDateSortedCursor.getInt(mStatusColumnId);
boolean isComplete = status == DownloadManager.STATUS_SUCCESSFUL
|| status == DownloadManager.STATUS_FAILED;
String localUri = mDateSortedCursor.getString(mLocalUriColumnId);
if (isComplete && localUri != null) {
String path = Uri.parse(localUri).getPath();
if (path.startsWith(Environment.getExternalStorageDirectory().getPath())
|| path.startsWith(Environment.getDataDirectory().getPath())) {//此处为删除源文件所添加的代码
String mediaProviderUri = mDateSortedCursor.getString(mMediaProviderUriId);
if (TextUtils.isEmpty(mediaProviderUri)) {
// downloads database doesn't have the mediaprovider_uri. It means
// this download occurred before mediaprovider_uri column existed
// in downloads table. Since MediaProvider needs the mediaprovider_uri to
// delete this download, just set the 'deleted' flag to 1 on this row
// in the database. DownloadService, upon seeing this flag set to 1, will
// re-scan the file and get the MediaProviderUri and then delete the file
mDownloadManager.markRowDeleted(downloadId);
return;
} else {
getContentResolver().delete(Uri.parse(mediaProviderUri), null, null);
// sometimes mediaprovider doesn't delete file from sdcard after deleting it
// from its db. delete it now
try {
File file = new File(path);
file.delete();
} catch (Exception e) {
Log.w(LOG_TAG, "file: '" + path + "' couldn't be deleted", e);
}
}
}
}
}
mDownloadManager.remove(downloadId);
}
【修改】删除记录时一起把源文件也删除
idh.code\packages\providers\DownloadProvider\ui\src\com\android\providers\downloads\ui\DownloadList.java
private void deleteDownload(long downloadId) {
if (moveToDownload(downloadId)) {
int status = mDateSortedCursor.getInt(mStatusColumnId);
boolean isComplete = status == DownloadManager.STATUS_SUCCESSFUL
|| status == DownloadManager.STATUS_FAILED;
String localUri = mDateSortedCursor.getString(mLocalUriColumnId);
if (isComplete && localUri != null) {
String path = Uri.parse(localUri).getPath();
if (path.startsWith(Environment.getExternalStorageDirectory().getPath())
|| path.startsWith(Environment.getDataDirectory().getPath())) {//此处为删除源文件所添加的代码
String mediaProviderUri = mDateSortedCursor.getString(mMediaProviderUriId);
if (TextUtils.isEmpty(mediaProviderUri)) {
// downloads database doesn't have the mediaprovider_uri. It means
// this download occurred before mediaprovider_uri column existed
// in downloads table. Since MediaProvider needs the mediaprovider_uri to
// delete this download, just set the 'deleted' flag to 1 on this row
// in the database. DownloadService, upon seeing this flag set to 1, will
// re-scan the file and get the MediaProviderUri and then delete the file
mDownloadManager.markRowDeleted(downloadId);
return;
} else {
getContentResolver().delete(Uri.parse(mediaProviderUri), null, null);
// sometimes mediaprovider doesn't delete file from sdcard after deleting it
// from its db. delete it now
try {
File file = new File(path);
file.delete();
} catch (Exception e) {
Log.w(LOG_TAG, "file: '" + path + "' couldn't be deleted", e);
}
}
}
}
}
mDownloadManager.remove(downloadId);
}
相关文章推荐
- Android (SpreadTurm)无T卡下载文件导致无法释放手机内存
- (android文件下载)下载链接中包含特殊字符--空格,中文等,导致无法识别处理方案
- Android Http下载文件到手机内存与SDCard
- android 默认浏览器 无法下载,此手机不支持此内容(自定义文件or APK文件看过了)
- android手机(平板)下载文件后,在文件管理软件中可以看到,通过mtp模式连接电脑后,无法在电脑上看到
- android 中可能导致内存无法释放的原因(更新中)
- Android手机ROOT之后更改字体文件导致无法启动的问题
- android手机自带浏览器无法识别apk文件
- WPF的BitmapImage的文件无法释放及内存泄露的问题
- “/proc/meminfo”文件记录了android手机的一些内存信息
- WPF的BitmapImage的文件无法释放及内存泄露的问题
- Android系列之音乐播放器的实现一(播放手机内存音频文件)
- 如何清理释放 Android 手机内存空间
- Android无法导入下载好的项目(和Eclipse中已经存在的项目命名一样导致冲突)解决办法
- Android 6.0权限导致dest.mkdirs() 一直返回false问题: 无法写入文件:
- Android开发实践经验谈:如何让各式手机浏览器可以直接下载apk安装文件且实现自动安装APP
- Android无法导入下载好的项目(和Eclipse中已经存在的项目命名一样导致冲突)解决的方法
- 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)
- Android 漫游之路------将文件保存到内存、SD以及获取手机内部存储与外部存储空间的大小
- Android无法导入下载好的项目(和Eclipse中已经存在的项目命名一样导致冲突)解决办法