Android将图片保存至相册刷新问题记录

部分机器可以通过sendBrocast实现。本人是MIUI系统,sendBrocast不生效,最终还是得通过调用系统扫描服务完成目的


final MediaScannerConnectClientClient scannerClient = new MediaScannerConnectClientClient(result);
                    final MediaScannerConnection scanner = new MediaScannerConnection(getActivity(), scannerClient);
                    scannerClient.setScanner(scanner);
                    scanner.connect();



public static class MediaScannerConnectClientClient implements MediaScannerConnectionClient {
        
        private MediaScannerConnection mScanner;
        
        private String mScanPath;
        
        public MediaScannerConnectClientClient(String scanPath) {
            mScanPath = scanPath;
        }
        
        public void setScanner(MediaScannerConnection con) {
            mScanner = con;
        }

        @Override
        public void onMediaScannerConnected() {
            mScanner.scanFile(mScanPath, "image/*");
        }

        @Override
        public void onScanCompleted(String path, Uri uri) {
            mScanner.disconnect();
        }
    } 


你可能感兴趣的:(Android将图片保存至相册刷新问题记录)