android 10.0SnapdragonCamera 照片存sd卡 点缩略图进不去的bug

bug:如标题

思路:

captureModule的setUpCameraOutputs调用MediaSaveService的ImageSaveTask,然后调用storage的insertImage返回一个uri,把uri传给MediaSaveService的onMediaSave,由于这个uri为空所以 点 不进去

修改storage的insertImage

private static Uri insertImage(ContentResolver resolver, ContentValues values, String path, Context context) {
    Uri uri = null;
    try {
        //uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
        if (sSaveSDCard) {
            Set<String> a=MediaStore.getExternalVolumeNames(context);
            String sdcardName=null;
            for (String s:a){
                if(!s.equals("external_primary")){
                    sdcardName=s;
                }
            }
            Uri inserUri = Images.Media.getContentUri(sdcardName);
            uri = resolver.insert(inserUri, values);
            if(uri==null) {
                String[] projection = {
                        "_id", "_data", "_display_name"
                };
                Cursor c = resolver.query(inserUri, projection, null, null, "_id DESC", null);
                if (c != null) {
                    Log.w(TAG, "c.number" + c.getCount());
                    if (c.moveToFirst()) {
                        int _id = c.getInt(0);
                        uri = Uri.parse(inserUri.toString()+"/"+_id);
                    }
                }
                c.close();
            }
        } else {
            uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
        }
    } catch (Throwable th) {
        // This can happen when the external volume is already mounted, but
        // MediaScanner has not notify MediaProvider to add that volume.
        // The picture is still safe and MediaScanner will find it and
        // insert it into MediaProvider. The only problem is that the user
        // cannot click the thumbnail to review the picture.
        Log.e(TAG, "Failed to write MediaStore" + th);
    }
    return uri;
}

在插入之后要通知媒体库更新

if (Storage.isSaveSDCard()) {
    String path1 =  Storage.generateFilepath(title, pictureFormat);
    Uri uri1 = Uri.fromFile(new File(path1));
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri1);
    sendBroadcast(intent);
    // return uri1;
}

video也是这个思路修改

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值