Now I learn that the .txt asset files get compressed, and openAssetFd
fails on compressed files!

Wow.

is there a workaround for this?

I just changed the extension to .jpg and it worked, but that's UGLY.

Any thoughts?

Thanks.


On Dec 4, 11:52 pm, Saied <[email protected]> wrote:
> I spoke too soon.
> It works ONCE and then it
>
> 12-04 22:38:05.330: WARN/System.err(763):
> java.io.FileNotFoundException: This file can not be opened as a file
> descriptor; it is probably compressed
>
> This is the routine in the Content Provider:
>
> @Override
> public AssetFileDescriptor openAssetFile(Uri uri, String mode) {
>                 String fileName = "asset_text.txt";
>                 AssetManager assetManager = this.getContext().getAssets();
>                 AssetFileDescriptor afd = null ;
>                 try {
>                         afd = assetManager.openFd(fileName);
>                 } catch (IOException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>                 }
>                 return afd;
>         }
>
> What I don't understand is why did it work once and no more? The file
> is still there, intact. Does it get compressed on the device? How can
> I read it reliably?
>
> Thanks.
>
> On Dec 4, 3:02 pm, Saied <[email protected]> wrote:
>
>
>
>
>
>
>
> > wow. that was dumb of me!! Thanks for pointing it out.
>
> > so I changed it to:
>
> > @Override
> >         public AssetFileDescriptor openAssetFile(Uri uri, String mode) {
> >                 String fileName = "asset_text_orig.txt";       // 
> > hardcoding the
> > file name for now
>
> >                 AssetManager assetManager = getAssets();
> >                 AssetFileDescriptor afd = assetManager.openFd(fileName);
> >                 return afd;
> >         }
>
> > and it WORKS!!
>
> > Thank you VERY much for your help and indulgence!
>
> > On Dec 4, 2:09 pm, skink <[email protected]> wrote:
>
> > > Saied wrote:
> > > > 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;
> > > >    }
>
> > > it will not work since you call openAssetFile recursively and you will
> > > get stack overflow error
>
> > > > 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.
>
> > > seehttp://developer.android.com/guide/topics/providers/content-providers...
>
> > > pskink

-- 
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

Reply via email to