I have an apk (App1) that has a raw resource (res/raw/mytextfile.txt) and I would like to read that text file from another apk (App2). I define a content provider in App1 and I override the openFile(Uri, String)
method as follows:
Resources res = getContext().getResources();
return res.openRawResourceFd(R.raw.mytextfile).getParcelFileDescriptor();
App2 does the following to try to get access to mytextfile.txt:
ContentResolver cr = getApplicationContext().getContentResolver();
ParcelFileDescriptor fd = cr.openFileDescriptor(uri, "r");
InputStream is = new FileInputStream(fd.getFileDescriptor());
BufferedReader bis = new BufferedReader(new InputStreamReader(is));
However, when I read and write out the contents of the BufferedReader, I get way more than just the contents of mytextfile.txt. Clearly I'm doing something wrong so I'd appreciate it if somebody could point me in the right direction.
Thanks,
Mirza
I played with this some more and found that the file desriptor returned to App2 is pointing to the App1 apk file. I wrote out the contents of the BufferedReader to a file and did a binary comparison to App1.apk. The two files were identical.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…