For more options, visit this group at http://groups.google.com/group/android-ndk?hl=.--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
First, if I simply put a file into res/raw, how can I make sure it is
not compressed? Or did you just mean that the text file is available
as-is anyway as soon as I access it through AssetManager, and as long
as I do not compress it myself somehow?
Secondly, AssetManager just allows the reading of files. However, I
also need writing files (at least during developing and debugging). I
already read two books about android, but still I haven't found full
insight on how to write raw files. The simplest way seams to be using
the sdcard for writing data, but that's hopefully not the end of the
story; could you point me to some starting point for writing files?
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
I want to avoid JNI....
So what is the best way to read and write from native code.
How to bundle the configuration files in to APK.
- This unzip also to read from APK without involving JNI.. but writing
(See e.g. frameworks/base/libs/utils/ZipFileRO.cpp .)
can't be possible right ?
Here the approach I'm thinking....
1. I need a config file (myconfig.cfg) when application boot up, and
it should be bundle up along with APK
Sol: Keep the file in res/raw or assets and use AssetManager to open
the file for reading.
2. On configuration change
Copy myconfig.cfg to another file myconfig-write.cfg with in
Applicaiton private directory and open it for writing... and pass the
FD to native code.
Quesiton: How to map FD returned by Java used in native code, as there
is no clear information in above replies ?
Is there any other best way , please give me some pointers.
regards
-Bytes
> > Not sure what "unmangle" means here.- Hide quoted text -
On Dec 8, 12:16 pm, Bytes <toyvenu.t...@gmail.com> wrote:
> Hi,
>
> But what about writing to these files ?
>
> On Nov 9, 2:21 am, fadden <fad...@android.com> wrote:
>
>
>
> > On Nov 7, 7:02 pm, Mike Gassman <mikeispretty...@gmail.com> wrote:
>
> > > Only problem is... I can't seem to find a way to get the files on to
> > > the Android device so I am able to read the data in. I would prefer
> > > some way to package these files into the apk so they can be installed
> > > with the package. I would like to be able to access these files
> > > without having to go through the java functions, which basically
> > > "unmangle" the files that the apk would generate if you put them into
> > > the assets or rsc directories.
>
> > If you don't want to call into Java at all, you can provide your own
> > "unzip" function and unpack the files directly from the APK yourself.
> > (See e.g. frameworks/base/libs/utils/ZipFileRO.cpp .)
>
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
1) Put the target file in the assets folder of you project.
You MUST rename the file so it has a .png extension, to fool the aapt
into not compressing it.
OR
You can tell aapt to not compress the file using the -0 command line
argument. But, I can not figure out how to specify that command line
argument using Eclipse. If anyone know how to do so, PLEASE rely.
2) On the Java Side you need to get three things:
a) Proper path to the apk file so you can open it on the native side.
b & c) The offset and length of the file you wish to read.
So, pass that string with the Path, and the two ints across the jni to
your native code.
3) On the native side, open the .apk file using fopen, and the path
that you passed in.
Do a fseek using the offset that you passed in to get to the proper
place in the apk bucket of bits.
Read the bytes from the file, using the length of the file that you
passed in.
Here is the Javacode to get the path, offset, and length:
// Get the path
String apkFilePath = null;
ApplicationInfo appInfo = null;
PackageManager packMgmr = mActivity.getPackageManager();
try
{
appInfo = packMgmr.getApplicationInfo
( "com.abc.YourPackageName", 0 );
apkFilePath = appInfo.sourceDir;
}
catch( NameNotFoundException e){
}
// Get the offset and length for the file: theUrl, that is in your
assets folder
AssetManager assetManager = mActivity.getAssets();
try {
// HACK till I figure out the aapt -0 options to not compress files
//String hackedUrl = theUrl.substring(0, theUrl.length()-3 ) + "png";
AssetFileDescriptor assFD = assetManager.openFd( hackedUrl );
if( assFD != null ) {
long offset = assFD.getStartOffset();
long fileSize = assFD.getLength();
assFD.close();
}
}
catch( IOException e) {}
Again. openFd will return NULL if your file has an extension other
than .png, or mp3...
Reading all the way above to Dianne wrote:
"Get the file descriptor with the Java APIs on Resources of
AssetManager and
hand that to your native code, such as:
http://developer.android.com/reference/android/content/res/AssetManag...)
Note that for those to work you need to make sure your data is stored
uncompressed. If you don't want to do that, you could use the higher-
level
APIs that return an InputStream and perform calls on it from your JNI
code
to read the data. "
Where I'm confused is in the native code, what JNIEnv* function would
need to be called to on either the AssetManager object or the
InputStream and what exactly would it return... an opened FILE
pointer?
If this is one of those RTFM question on general JNI usage... please
let me know and I'll hit the books harder.
Thanks,
Jeremiah
On Dec 18, 11:09 am, Keith <keithrvic...@gmail.com> wrote:
> If you want to READ afilethat you package with your app, this will
> work:
> Dianne explained this rather breifly. I will expand.
>
> 1) Put the targetfilein the assets folder of you project.
> You MUST rename thefileso it has a .png extension, to fool the aapt
> into not compressing it.
> OR
> You can tell aapt to not compress thefileusing the -0 command line
> argument. But, I can not figure out how to specify that command line
> argument using Eclipse. If anyone know how to do so, PLEASE rely.
>
> 2) On the Java Side you need to get three things:
> a) Proper path to the apkfileso you can open it on the native side.
> b & c) The offset and length of thefileyou wish to read.
>
> So, pass that string with the Path, and the two ints across the jni to
> your native code.
>
> 3) On the native side, open the .apkfileusing fopen, and the path
> that you passed in.
> Do a fseek using the offset that you passed in to get to the proper
> place in the apk bucket of bits.
> Read the bytes from thefile, using the length of thefilethat you
> passed in.
>
> Here is the Javacode to get the path, offset, and length:
>
> // Get the path
> String apkFilePath = null;
> ApplicationInfo appInfo = null;
> PackageManager packMgmr = mActivity.getPackageManager();
> try
> {
> appInfo = packMgmr.getApplicationInfo
> ( "com.abc.YourPackageName", 0 );
> apkFilePath = appInfo.sourceDir;
> }
> catch( NameNotFoundException e){
> }
>
> // Get the offset and length for thefile: theUrl, that is in your
> assets folder
>
> AssetManager assetManager = mActivity.getAssets();
> try {
>
> // HACK till I figure out the aapt -0 options to not compress files
> //String hackedUrl = theUrl.substring(0, theUrl.length()-3 ) + "png";
>
> AssetFileDescriptor assFD = assetManager.openFd( hackedUrl );
> if( assFD != null ) {
> long offset = assFD.getStartOffset();
> long fileSize = assFD.getLength();
> assFD.close();
> }
> }
> catch( IOException e) {}
>
> Again. openFd will return NULL if yourfilehas an extension other