zoukankan      html  css  js  c++  java
  • MediaStore扫描 & 向MediaStore中插入文件记录

    通知MediaStore扫描某个文件:
    private void scanSingleFile(String filePath) { if (filePath == null) { return; } // broadcast to scan file boolean bmnt = Environment.getExternalStorageDirectory().getPath() .startsWith("/mnt"); bmnt = mDownloadDestination .equalsIgnoreCase(UpDownloadUtils.DOWNLOAD_DEST_SDCARD) ? bmnt : false; File file = new File(bmnt ? ("/mnt" + filePath) : filePath); MediaScannerConnection.scanFile(mContext, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { ContentResolver cr = mContext.getContentResolver(); long datemodified = 0; long dateadded = 0; Cursor cursor = cr.query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { datemodified = cursor.getLong(cursor .getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED)); dateadded = cursor.getLong(cursor .getColumnIndex(MediaStore.MediaColumns.DATE_ADDED)); cursor.close(); } ContentValues values = new ContentValues(); if (datemodified > 0 && String.valueOf(datemodified).length() > 10) { values.put(MediaStore.MediaColumns.DATE_MODIFIED, datemodified / 1000); } if (dateadded > 0 && String.valueOf(dateadded).length() > 13) { values.put(MediaStore.MediaColumns.DATE_ADDED, dateadded / 1000); } if (values.size() > 0) { cr.update(uri, values, null, null); } } }); }

    向MediaStore中插入文件记录
                ContentValues newValues = new ContentValues(6);
                String title = FileName.substring(0, pointIndex);
                newValues.put(MediaStore.Images.Media.TITLE,
                        FileName.substring(0, pointIndex));
                newValues.put(MediaStore.Images.Media.DISPLAY_NAME,
                        sourceFile.getName());
                newValues.put(MediaStore.Images.Media.DATA, sourceFile.getPath());
                newValues.put(MediaStore.Images.Media.DATE_MODIFIED,
                        System.currentTimeMillis() / 1000);
                newValues.put(MediaStore.Images.Media.SIZE, sourceFile.length());
                newValues.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
                uri = contentResolver.insert(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, newValues);
    
    
    
     
  • 相关阅读:
    process crashed and the client did not handle it, not reloading the page because we reached the maximum number of attempts
    mac 查看ip
    axios和vue-axios的关系
    export default 和 export 区别
    Mac 编辑hosts文件
    npm --save-dev --save 的区别
    CommonHelper 公共类
    2.06StuModify.aspx(修改姓名,性别,所在班级)
    linux网桥浅析
    Bridge的数据在内核处理流程
  • 原文地址:https://www.cnblogs.com/androidwsjisji/p/2737604.html
Copyright © 2011-2022 走看看