예제 #1
0
        public override ParcelFileDescriptor OpenDocument(string documentId, string mode, CancellationSignal signal)
        {
            Log.Verbose(TAG, "openDocument, mode: " + mode);
            // It's OK to do network operations in this method to download the document, as long as you
            // periodically check the CancellationSignal.  If you have an extremely large file to
            // transfer from the network, a better solution may be pipes or sockets
            // (see ParcelFileDescriptor for helper methods).

            File file       = GetFileForDocId(documentId);
            var  accessMode = ParcelFileDescriptor.ParseMode(mode);

            bool isWrite = (mode.IndexOf('w') != -1);

            if (isWrite)
            {
                // Attach a close listener if the document is opened in write mode.
                try {
                    var handler = new Handler(Context.MainLooper);
                    return(ParcelFileDescriptor.Open(file, accessMode, handler, new MyOnCloseListener(documentId)));
                } catch (IOException) {
                    throw new FileNotFoundException("Failed to open document with id " + documentId + " and mode " + mode);
                }
            }
            else
            {
                return(ParcelFileDescriptor.Open(file, accessMode));
            }
        }