Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get ParcelFileDescriptor for file content?

I use eclipse-indigo and android 2.3.3_r1 and I download a string from a server in network.It is the content of docx file.

Can I receive a ParcelFileDescritor from it? I guess that MemoryFile can help me, because I saw getParcelFileDescriptor() method for it here and here, but when I'm writing my code in eclipse, I cannot find method getParcelFileDescriptor() in class android.os.MemoryFile.

Finally this is my question: is it possible without using socket()?

like image 887
hasanghaforian Avatar asked Dec 13 '11 10:12

hasanghaforian


1 Answers

@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;
    }
like image 190
Shridutt Kothari Avatar answered Oct 19 '22 23:10

Shridutt Kothari