How to get ParcelFileDescriptor for file contents?

I am using eclipse-indigo and android 2.3.3_r1 and I am downloading a string from a server on the network. This is the contents of the docx file.

Can I get ParcelFileDescritor from it? I think MemoryFile can help me because I saw the getParcelFileDescriptor() method here and here , but when I write my code in eclipse I cannot find the getParcelFileDescriptor() method in the android.os.MemoryFile class.

Finally, this is my question: maybe without using socket ()

+6
source share
2 answers

getParcelFileDescriptor() is a private method of the package, so I could not find it in my class (i.e. in another package). I tried to access it by reflection, but finally I understand that it returns the appropriate ParcelFileDescritor if and only if we create our MemoryFile as a link to an existing memory file, in which case we want a File descriptor from this existing memory file . Therefore, this method cannot help us. It also seems that in later versions of Android this method is completely ignored and removed from the class.

0
source
 @Override public ParcelFileDescriptor openFile(Uri uri){ File f=new File(getContext().getFilesDir(),uri.getLastPathSegment()); ParcelFileDescriptor pfd; try { pfd=ParcelFileDescriptor.open(f,ParcelFileDescriptor.MODE_READ_ONLY); } catch ( FileNotFoundException e) { e.printStackTrace(); return null; } return pfd; } 
+6
source

Source: https://habr.com/ru/post/903669/


All Articles