On Sun, Aug 30, 2009 at 3:17 PM, deki <dcec...@gmail.com> wrote:
> Hi list,
> How can I get / generate a path for use in fopen in native code to
> open a file say in res/drawable?
> I realize it might not be possible entirely in native to generate that
> path, even If I have to pass the path from java to c++ that would be
> fine.
Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.
On Mon, Aug 31, 2009 at 1:39 AM, Dianne Hackborn<hack...@android.com> wrote: > You can't; those files are packed into a single .zip and can't be > individually open.
One workaround is to put (and rename) the files into lib folder ... I did this in some JNI application ...
I'm not sure about Resources, but you can do it with Assets through a
hack...
1. In Java, get your apk file path through
PackageManager.getApplicationInfo(...)
2. In java, get offset and size of asset in the apk through
Context.getAssets().openFd().getStartOffset()/getLength()
3. In JNI/C, open your apk file, seek to offset and read size bytes
into a buffer
4. ???
5. Profit!
I leave no guarantees on forward compatibility and/or portability, but
it works... :)
regards
Anders
On Aug 31, 12:17 am, deki <dcec...@gmail.com> wrote:
> How can I get / generate a path for use in fopen in native code to
> open a file say in res/drawable?
> I realize it might not be possible entirely in native to generate that
> path, even If I have to pass the path from java to c++ that would be
> fine.
Um be sure you close the fd. And really, just pass the fd along with the
start offset and and offset through to JNI. I guarantee that will work, it
is how the API is intended to be used (regardless of native code). Assuming
that the start offset and end offset are absolute positions in your .apk is
not guaranteed to work in the future. (For example, what happens if one day
we decide that when an app is installed we unpack its .apk into individual
files?)
On Fri, Oct 9, 2009 at 5:34 AM, Anders Johansson <svi...@gmail.com> wrote:
> I'm not sure about Resources, but you can do it with Assets through a
> hack...
> 1. In Java, get your apk file path through
> PackageManager.getApplicationInfo(...)
> 2. In java, get offset and size of asset in the apk through
> Context.getAssets().openFd().getStartOffset()/getLength()
> 3. In JNI/C, open your apk file, seek to offset and read size bytes
> into a buffer
> 4. ???
> 5. Profit!
> I leave no guarantees on forward compatibility and/or portability, but
> it works... :)
> regards
> Anders
> On Aug 31, 12:17 am, deki <dcec...@gmail.com> wrote:
> > Hi list,
> > How can I get / generate a path for use in fopen in native code to
> > open a file say in res/drawable?
> > I realize it might not be possible entirely in native to generate that
> > path, even If I have to pass the path from java to c++ that would be
> > fine.
Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.
Hi there, from reading this thread, I am thinking the best way for me
to acess all my assets, from native code, would be to bundle all my
assets into a single WAD/DAT file, and then include this as an asset
for the Java side to see. There are then a couple of Java side API
calls that I can make, to get the files start address in memory, and
also ths size, I can therefore just pass these two values across to
the native code and access it. Is this correct?
Would it be at all possible for someone to provide me with the Java
side calls to do this? I am looking through the various resource
functions and am not sure which one I need, and making sure if any
file handles are opened making sure they are closed etc.
Finally, roughly on topic, I also want to be able to write out a save/
settings file somewhere, could anyone give me in a nudge in the right
direction for what I should be doing here? I'd like to write out this
file from the native side ideally, but if that simply isn't possible I
could put the data I want to write out in to memory, and then get the
Java code to write this data out, presumably?
Many thanks for all your help,
Steve
On Oct 9, 5:50 pm, Dianne Hackborn <hack...@android.com> wrote:
> Um be sure you close the fd. And really, just pass the fd along with the
> start offset and and offset through to JNI. I guarantee that will work, it
> is how the API is intended to be used (regardless of native code). Assuming
> that the start offset and end offset are absolute positions in your .apk is
> not guaranteed to work in the future. (For example, what happens if one day
> we decide that when an app is installed we unpack its .apk into individual
> files?)
> On Fri, Oct 9, 2009 at 5:34 AM, Anders Johansson <svi...@gmail.com> wrote:
> > I'm not sure about Resources, but you can do it with Assets through a
> > hack...
> > 1. In Java, get your apk file path through
> > PackageManager.getApplicationInfo(...)
> > 2. In java, get offset and size of asset in the apk through
> > Context.getAssets().openFd().getStartOffset()/getLength()
> > 3. In JNI/C, open your apk file, seek to offset and read size bytes
> > into a buffer
> > 4. ???
> > 5. Profit!
> > I leave no guarantees on forward compatibility and/or portability, but
> > it works... :)
> > regards
> > Anders
> > On Aug 31, 12:17 am, deki <dcec...@gmail.com> wrote:
> > > Hi list,
> > > How can I get / generate a path for use in fopen in native code to
> > > open a file say in res/drawable?
> > > I realize it might not be possible entirely in native to generate that
> > > path, even If I have to pass the path from java to c++ that would be
> > > fine.
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails. All such
> questions should be posted on public forums, where I and others can see and
> answer them.