Why not use reflection to get the PFD? There is a method for that in the
MemoryFile class.
Op woensdag 4 juli 2012 09:55:32 UTC+2 schreef rtindru het volgende:
>
> I have an application that needs to Base64 decode on the fly a bitmap
> image & render it on the ImageView.
> I am using a custom content provider to do this. When the openFile method
> is called - I in this case chose to use a normal non-encoded file for
> testing purpose.
> Now I create a MemoryFile from the imagefile (after decoding) & have to
> return a ParcelFileDescriptor of the MemoryFile.
>
> I tried reflection & got the FileDescriptor of the MemoryFile but am
> unable to get the ParcelFileDescriptor from the FileDescriptor
> I tried the dup, adoptFD methods but the ParcelFileDescriptor was invalid.
> Kindly help me out here.
> Cheers
> Indru
>
> public ParcelFileDescriptor openFile(Uri uri, String mode)
> throws FileNotFoundException {
> File openFile = new File(uri.toString());
> try {
> MemoryFile file = new MemoryFile(null, (int)
> openFile.length());
> ParcelFileDescriptor pfd = ParcelFileDescriptor.open(openFile,
> ParcelFileDescriptor.MODE_READ_ONLY);
> AutoCloseInputStream in = new AutoCloseInputStream(pfd);
> byte[] buffer = new byte[in.available()];
> //Should do decoding here - skipped to test the code
> in.read(buffer, 0, buffer.length);
> file.writeBytes(buffer, 0, 0, buffer.length);
> Method getFileDescriptorMethod = file.getClass().getMethod(
> "getFileDescriptor");
> FileDescriptor out = (FileDescriptor) getFileDescriptorMethod
> .invoke(file);
> // I have the FD, now how to return a PFD?? Any ideas? dup & adoptFD dont
> work - the PFD is invalid.
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en