Thanks again!

Actually, this seems to be working on the ContentProvider now:

public AssetFileDescriptor openAssetFile(Uri uri, String mode) {
                String fileName = "asset_text_orig.txt";
                URI uri1 = URI.create(fileName);
                AssetFileDescriptor parcel =  this.openAssetFile(uri1, mode);  
//
for testing purposes, I hardwired this to uri1 >
"asset_text_orig.txt";
                return parcel;
        }

Now, how do I read this from an app?

        String packageName = "com.example.text.cp";
        FileInputStream fstream = new FileInputStream("content://" +
packageName); // there is only one kind of file exposed
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine = br.readLine();

        ...

Or should I include openAssetFile(Uri uri, String mode) at the end of
the uri goint to FileInputStream?

Thank you very much for your help so far.



On Dec 3, 11:30 am, skink <psk...@gmail.com> wrote:
> Saied wrote:
> > Thanks Pskink!
>
> > Per your suggestion, I have created a content provider and tried this:
>
> > @Override
> >    public AssetFileDescriptor openAssetFile1(Uri uri, String mode) {
> >            String fileName = "asset_text_orig.txt";
> >            ParcelFileDescriptor parcel = openAssetFile(fileName,
> > ParcelFileDescriptor.MODE_READ_ONLY);
>
> >            return parcel;
> >    }
>
> > there is a conflict as parcel  type is ParcelFileDescriptor, but I
> > need to return AssetFileDescriptor. How do I resolve that.
>
> > And once this is corrected? How do I read this?
>
> > Thanks.
>
> > On Dec 3, 9:21 am, skink <psk...@gmail.com> wrote:
> > > Saied wrote:
> > > > Thanks.
>
> > > > I did create a contentProvider with a single asset file.
>
> > > > I also tried  ParcelFileDescriptor
>
> > > > @Override
> > > > public ParcelFileDescriptor openFile(Uri uri, String mode) throws
> > > > FileNotFoundException{
> > > > ...
> > > > ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file,
> > > > ParcelFileDescriptor.MODE_READ_ONLY);
> > > > return parcel;
> > > > }
>
> > > > but  could not make it work. Then thought just making a regular app
> > > > would be less tricky.
> > > > Now I do have the app which WRITES a worldReadable file that I can
> > > > read from my other app.
> > > > But there is that extra step I am trying to avoid.
>
> > > > I understand reading the asset file may be impossible.
>
> > > > Would it be easier if I read a raw file?
>
> > > > Or should I definitely go back to making a content provider and try to
> > > > read its asset?
>
> > > > Thank you very muchfor your help.
>
> > > create custom ContententProvider and try to override openAssetFile()
> > > method
>
> > > pskink
>
> use this: developer.android.com/reference/android/content/res/
> AssetManager.html#openFd(java.lang.String)
>
> pskink

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to