James SDC | 1 Sep 19:48 2009
Picon

How to Access the SD File System?


Hi,

I am trying to use JNI (through NDK) to open a file and read/write to
the file. Does anyone know how to do that, and is the root access
necessary?

In addition, can a Java Android application access the file in a SD
card without root access necessary?

Thanks.

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

PK | 2 Sep 10:24 2009
Picon

Re: How to Access the SD File System?


Don't know how to access SD card using JNI, but have java app example
how to list files in the directory:

public String[] getFilesList(){
String fileList[] = null;

String sdcardState = android.os.Environment.getExternalStorageState();
	if (sdcardState.contentEquals(android.os.Environment.MEDIA_MOUNTED)){
		dirName = android.os.Environment.getExternalStorageDirectory() +
File.separator + "some_directory";
		File dir = new File(dirName);
		FilenameFilter filter = new FilenameFilter() {
		public boolean accept(File file,String name){
				return (name.endsWith(".png") || name.endsWith(".jpg"));
			}
		};

		fileList = dir.list(filter);
		return fileList;
	}
	return null;
}

to read files use standart Java java.io.Reader or java.io.InputStream
subclasses.

On Sep 1, 7:48 pm, James SDC <hanzon... <at> gmail.com> wrote:
> Hi,
>
(Continue reading)

WoodManEXP | 2 Sep 16:43 2009
Picon

Re: How to Access the SD File System?


I am working on the exact same thing right now (using JNI through NDK
to access files)!

I have found that the native java.io read methods are are giving good
performance when pulling in large binary byte[] arrays from /sdcard/.
Problem is that is the only thing they can read directly from the file
system. If you need to convert that binary data to another type like
char or short or int you are SOL because you either code bit shifting
tricks to do it yourself or use java.nio classes. Both methods are
slower than slow with large arrays.

To your question, it was easy to access the /sdcard/. Just append "/
sdcard/" to the beginnng of the file name. No special permssions got
in my way. (Need to configure an /sdcard/ for the avd if you have not
done so already).

Have you been successful installing and configuring NDK?

On Sep 1, 1:48 pm, James SDC <hanzon... <at> gmail.com> wrote:
> Hi,
>
> I am trying to use JNI (through NDK) to open a file and read/write to
> the file. Does anyone know how to do that, and is the root access
> necessary?
>
> In addition, can a Java Android application access the file in a SD
> card without root access necessary?
>
> Thanks.
(Continue reading)

James SDC | 2 Sep 19:32 2009
Picon

Re: How to Access the SD File System?


Hi PK,

Thank you very much for your information. I have figured out the file
access to the SD card in Java. Basically, it is working without root
access necessary.

Hi WoodManEXP,

Are you using Java or JNI to access the file on SD card? It sounds to
me that you are using Java. The problem I have is to use JNI to access
the file.

First of all, I try to use fopen() to open an existing file on SD
card, then I want to use fread() to read the file, and use fwrite() to
write to the file.

Let say I call fopen("/sdcard/mytest.dat", "r+") to open the existing
file. On HTC Hero, I got errno = 13, which is permission denied. Then
I change the phone image and grant the root access according to some
sayings on the Internet. After that, the fopen() returns me success,
but fread() returns me errno = 2, which is "no such file or
directory."

The error of fread() totally does not make sense to me, and I wonder
if it is caused by the phone image change.

WoodManEXP, what is your experience with this, and how do you exactly
do to access the file from JNI? Thank you in advance!

(Continue reading)

James SDC | 2 Sep 20:22 2009
Picon

Re: How to Access the SD File System?


Hi WoodManEXP,

I may want to try on the Emulator as well. So how to configuration
NDK, and how to configuration ADV?

Thank you very much!
James.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-ndk <at> googlegroups.com
To unsubscribe from this group, send email to android-ndk+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en
-~----------~----~----~----~------~----~------~--~---

WoodManEXP | 2 Sep 21:47 2009
Picon

Re: How to Access the SD File System?


I am still working through the NDK configuration and so don't know
enough yet to help. Configuring the /sdcard/ for the emulator is very
easy. Use the tools/android command to make an avd, maybe like this

android create avd -n my_avd -t 2 -c 256M

This will make an 1.5 SDK emulator with a 256M /sdcard/.

See http://developer.android.com/guide/developing/tools/avd.html

Hope that is what you wer asking.

On Sep 2, 2:22 pm, James SDC <hanzon... <at> gmail.com> wrote:
> Hi WoodManEXP,
>
> I may want to try on the Emulator as well. So how to configuration
> NDK, and how to configuration ADV?
>
> Thank you very much!
> James.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-ndk <at> googlegroups.com
To unsubscribe from this group, send email to android-ndk+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en
-~----------~----~----~----~------~----~------~--~---

James SDC | 2 Sep 22:46 2009
Picon

Re: How to Access the SD File System?


Hi WoodManEXP,

I usually use Visual Studio to edit the c code. Sometimes, I use Vim
to make it simpler.
I have added a SD card to my emulator now, and see how it is going on
emulator.

Hi Dianne,

You mentioned that Java and JNI have the same permissions. However,
why can my Java application be able to open/read/write to the file on
SD card, but the fopen("/sdcard/mytest.dat", "r+")  in JNI gets
"permission denied"?

Can you point out how to open/read/write the file on SD card, by using
JNI?

Thanks,
James.

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

Dianne Hackborn | 2 Sep 23:57 2009

Re: How to Access the SD File System?

On Wed, Sep 2, 2009 at 1:46 PM, James SDC <hanzonliu <at> gmail.com> wrote:

You mentioned that Java and JNI have the same permissions. However,
why can my Java application be able to open/read/write to the file on
SD card, but the fopen("/sdcard/mytest.dat", "r+")  in JNI gets
"permission denied"?

I don't know, but all the Java code does is open the file, I can assure you.  You could try using the lower-level open() call.  And if you look at the filesystem, you will see that all of the files on the SD card are world readable.

--
Dianne Hackborn
Android framework engineer
hackbod <at> android.com

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.


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

Mine | 3 Sep 03:26 2009
Picon

Re: How to Access the SD File System?

Hi James,

    I'm using Emulator to do the same thing as you did, which is using fopen to open a file, and fread to read the file. Everything works fine.
    The difference is that I only need to read the file, so the fopen parameter is "rb". So I suggest that you try read the file first by fopen with "rb", then try write to see if anything different.

BRs,
Lei Yu

On Thu, Sep 3, 2009 at 4:46 AM, James SDC <hanzonliu <at> gmail.com> wrote:

Hi WoodManEXP,

I usually use Visual Studio to edit the c code. Sometimes, I use Vim
to make it simpler.
I have added a SD card to my emulator now, and see how it is going on
emulator.

Hi Dianne,

You mentioned that Java and JNI have the same permissions. However,
why can my Java application be able to open/read/write to the file on
SD card, but the fopen("/sdcard/mytest.dat", "r+")  in JNI gets
"permission denied"?

Can you point out how to open/read/write the file on SD card, by using
JNI?

Thanks,
James.




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

James SDC | 4 Sep 02:43 2009
Picon

Re: How to Access the SD File System?


Hi Lei Yu,

Yes, it is working now to me. I have tried both fopen() and open(),
and they all are working to me on both the emulator and the phone.
Thanks for all of you to help me out.

Best Regards,
James.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-ndk <at> googlegroups.com
To unsubscribe from this group, send email to android-ndk+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en
-~----------~----~----~----~------~----~------~--~---

Sureshbabu | 15 Oct 08:31 2009
Picon

Re: How to Access the SD File System?


Hello All,

I am new to this android platform. Can i get some information on
developing JNI code (file read/write)?

I am using windows OS for development (eclipse).

How to develope JNI and how to use it in android java application?

Anyone can help on this.

In advance Thanks Much.

-tsbabu.

On Sep 4, 5:43 am, James SDC <hanzon... <at> gmail.com> wrote:
> Hi Lei Yu,
>
> Yes, it is working now to me. I have tried both fopen() and open(),
> and they all are working to me on both the emulator and the phone.
> Thanks for all of you to help me out.
>
> Best Regards,
> James.

Jack Palevich | 15 Oct 15:14 2009
Picon

Re: How to Access the SD File System?

Sorry that everything is so confusing. Windows development is unfortunately different than Android development. (Android development is pretty similar to Unix/Linux development.)


Some suggestions:

+ Learn the standard Linux routines for file i/o. Do a web search for "fopen" or "stdio".

+ Learn how JNI works.  The Android implementation of JNI is very similar to the standard Java implementation, so you can use the documentation for the standard version to learn how to use the Android version.

+ Learn how the NDK works. There are documents and sample code in the NDK.

On Wed, Oct 14, 2009 at 11:31 PM, Sureshbabu <sureshbabu.thota <at> gmail.com> wrote:

Hello All,

I am new to this android platform. Can i get some information on
developing JNI code (file read/write)?

I am using windows OS for development (eclipse).

How to develope JNI and how to use it in android java application?

Anyone can help on this.

In advance Thanks Much.

-tsbabu.

On Sep 4, 5:43 am, James SDC <hanzon... <at> gmail.com> wrote:
> Hi Lei Yu,
>
> Yes, it is working now to me. I have tried both fopen() and open(),
> and they all are working to me on both the emulator and the phone.
> Thanks for all of you to help me out.
>
> Best Regards,
> James.




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

Jack Palevich | 15 Oct 15:17 2009
Picon

Re: How to Access the SD File System?

D'Oh, I think I should have said:


+ Learn how the Android permission system works. Starting with the Android 1.6 SDK, your apk has to have this permission in its manifest in order to be able to write to the SD card:

uses-permission 
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 


On Thu, Oct 15, 2009 at 6:14 AM, Jack Palevich <jackpal <at> google.com> wrote:
Sorry that everything is so confusing. Windows development is unfortunately different than Android development. (Android development is pretty similar to Unix/Linux development.)

Some suggestions:

+ Learn the standard Linux routines for file i/o. Do a web search for "fopen" or "stdio".

+ Learn how JNI works.  The Android implementation of JNI is very similar to the standard Java implementation, so you can use the documentation for the standard version to learn how to use the Android version.

+ Learn how the NDK works. There are documents and sample code in the NDK.

On Wed, Oct 14, 2009 at 11:31 PM, Sureshbabu <sureshbabu.thota <at> gmail.com> wrote:

Hello All,

I am new to this android platform. Can i get some information on
developing JNI code (file read/write)?

I am using windows OS for development (eclipse).

How to develope JNI and how to use it in android java application?

Anyone can help on this.

In advance Thanks Much.

-tsbabu.

On Sep 4, 5:43 am, James SDC <hanzon... <at> gmail.com> wrote:
> Hi Lei Yu,
>
> Yes, it is working now to me. I have tried both fopen() and open(),
> and they all are working to me on both the emulator and the phone.
> Thanks for all of you to help me out.
>
> Best Regards,
> James.





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

Sureshbabu | 21 Oct 07:45 2009
Picon

Re: How to Access the SD File System?


Hi Jack,

Thank you very much for your quick response.

I am developing android application in windows platform with Eclipse
editor.
Android-ndk available for windows platform. So can we develop the jni
code in windows platform (eclipse editor)?

-tsbabu.

On Oct 15, 6:17 pm, Jack Palevich <jack... <at> google.com> wrote:
> D'Oh, I think I should have said:
> + Learn how the Android permission system works. Starting with the Android
> 1.6 SDK, your apk has to have this permission in its manifest in order to be
> able to write to the SD card:
>
> uses-permission
> android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
>
>
>
> On Thu, Oct 15, 2009 at 6:14 AM, Jack Palevich <jack... <at> google.com> wrote:
> > Sorry that everything is so confusing. Windows development is unfortunately
> > different than Android development. (Android development is pretty similar
> > to Unix/Linux development.)
> > Some suggestions:
>
> > + Learn the standard Linux routines for file i/o. Do a web search for
> > "fopen" or "stdio".
>
> > + Learn how JNI works.  The Android implementation of JNI is very similar
> > to the standard Java implementation, so you can use the documentation for
> > the standard version to learn how to use the Android version.
>
> > + Learn how the NDK works. There are documents and sample code in the NDK.
>
> > On Wed, Oct 14, 2009 at 11:31 PM, Sureshbabu <sureshbabu.th... <at> gmail.com>wrote:
>
> >> Hello All,
>
> >> I am new to this android platform. Can i get some information on
> >> developing JNI code (file read/write)?
>
> >> I am using windows OS for development (eclipse).
>
> >> How to develope JNI and how to use it in android java application?
>
> >> Anyone can help on this.
>
> >> In advance Thanks Much.
>
> >> -tsbabu.
>
> >> On Sep 4, 5:43 am, James SDC <hanzon... <at> gmail.com> wrote:
> >> > Hi Lei Yu,
>
> >> > Yes, it is working now to me. I have tried both fopen() and open(),
> >> > and they all are working to me on both the emulator and the phone.
> >> > Thanks for all of you to help me out.
>
> >> > Best Regards,
> >> > James.- Hide quoted text -
>
> - Show quoted text -
Dianne Hackborn | 2 Sep 20:58 2009

Re: How to Access the SD File System?

Native code and Java have the same permissions.  After all, your Java call is just boiling down to a native open call.

On Wed, Sep 2, 2009 at 10:32 AM, James SDC <hanzonliu <at> gmail.com> wrote:

Hi PK,

Thank you very much for your information. I have figured out the file
access to the SD card in Java. Basically, it is working without root
access necessary.

Hi WoodManEXP,

Are you using Java or JNI to access the file on SD card? It sounds to
me that you are using Java. The problem I have is to use JNI to access
the file.

First of all, I try to use fopen() to open an existing file on SD
card, then I want to use fread() to read the file, and use fwrite() to
write to the file.

Let say I call fopen("/sdcard/mytest.dat", "r+") to open the existing
file. On HTC Hero, I got errno = 13, which is permission denied. Then
I change the phone image and grant the root access according to some
sayings on the Internet. After that, the fopen() returns me success,
but fread() returns me errno = 2, which is "no such file or
directory."

The error of fread() totally does not make sense to me, and I wonder
if it is caused by the phone image change.

WoodManEXP, what is your experience with this, and how do you exactly
do to access the file from JNI? Thank you in advance!





--
Dianne Hackborn
Android framework engineer
hackbod <at> android.com

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.


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

WoodManEXP | 2 Sep 21:41 2009
Picon

Re: How to Access the SD File System?


Hi James,

You are right, I am accessing the /sdcard/ via Java and my plan is to
begin accessing through JNI. I have seen posts that say it may be
possible to pass an open FileInputStream to the JNI and get the fd
from it. But there are fre more steps remaining to get the NDK going
before I get to that part. Sorry to not be of more help at this point.

BTW, are you on Windows and if so what are you using to edit the C
code files?

Thank you,

On Sep 2, 1:32 pm, James SDC <hanzon... <at> gmail.com> wrote:
> Hi PK,
>
> Thank you very much for your information. I have figured out the file
> access to the SD card in Java. Basically, it is working without root
> access necessary.
>
> Hi WoodManEXP,
>
> Are you using Java or JNI to access the file on SD card? It sounds to
> me that you are using Java. The problem I have is to use JNI to access
> the file.
>
> First of all, I try to use fopen() to open an existing file on SD
> card, then I want to use fread() to read the file, and use fwrite() to
> write to the file.
>
> Let say I call fopen("/sdcard/mytest.dat", "r+") to open the existing
> file. On HTC Hero, I got errno = 13, which is permission denied. Then
> I change the phone image and grant the root access according to some
> sayings on the Internet. After that, the fopen() returns me success,
> but fread() returns me errno = 2, which is "no such file or
> directory."
>
> The error of fread() totally does not make sense to me, and I wonder
> if it is caused by the phone image change.
>
> WoodManEXP, what is your experience with this, and how do you exactly
> do to access the file from JNI? Thank you in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-ndk <at> googlegroups.com
To unsubscribe from this group, send email to android-ndk+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en
-~----------~----~----~----~------~----~------~--~---


Gmane