您的位置:首页 > 移动开发 > Android开发

Android (SpreadTurm)无T卡下载文件导致无法释放手机内存

2012-11-15 09:07 966 查看
SpreadTurm在无T卡情况下使用/data/internal_memory路径存储下载文件,在删除文件进行路径匹配时未包含此路径

增加此路径前缀匹配过程.

详细路径: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);

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐