| Author |
Message |
ppmoore Freshman

Joined: 02 Apr 2009 Posts: 9
|
Posted: Thu Apr 02, 2009 5:52 pm Post subject: How to access a read-only package file on G1 phone? |
|
|
I've been reading the previous replies here, and they nearly answer my question, well, my two questions
I've been experimenting with an application that reads a text file containing a dictionary of words. When I sign and publish this app, I want to include the text file in the package. At the moment, I keep the text file in the /data/app-private directory. On the emulator, I test this by first copying the text file to this directory using eclipse's DDMS perspective, and it works.
When I try to do the same on the G1 phone, I cannot copy the text file to the /data/app-private directory. Browsing the G1's file system using eclipse, I notice that there is a /data directory, but is empty. It seems that this is a read-only file system.
Q1: When preparing the package to install on the phone, how do I specify that the text file is also a part of the package? If the text file is part of the package, how do I specify its location? At the moment, my code specifies a hard-coded location like this:
| Code: | String fileName = "file.txt";
String dirName = "/data/app-private";
File filePath = new File( dirName, fileName);
BufferedReader input = new BufferedReader(new FileReader(aFileName));
try
{
// Loop to count lines in the file
while( input.readLine() != null )
{
i++;
}
}
|
Q2: I suppose I should avoid hard-coding the file's location. I read earlier in this thread that I should use the activity method openFileInput(). Do I need to specify the file's location in this case?
| Code: | FileInputStream stream = openFileInput("file.txt");
InputStreamReader osw = new InputStreamReader(stream); |
Thanks again for the great site. I read earlier that you were studying for exams. How do you find the time?
Many thanks,
Paul
Can someone help?
Paul |
|
| Back to top |
|
 |
|
|
 |
songotho Developer

Joined: 03 Mar 2009 Posts: 35
|
Posted: Mon Apr 20, 2009 3:38 pm Post subject: |
|
|
Hi,
The tutorial is work with file, so I would not find any introductions about file zip. Would you introduce about working with file zip (i.e: zip and unzip file...). How do I secure the file in Android?
Thanks,
--Alex |
|
| Back to top |
|
 |
ppmoore Freshman

Joined: 02 Apr 2009 Posts: 9
|
Posted: Tue Apr 21, 2009 9:00 am Post subject: |
|
|
| I'm sorry, I am an Android beginner. I can't help you. |
|
| Back to top |
|
 |
shyjumon.n Freshman

Joined: 18 Mar 2009 Posts: 9
|
Posted: Mon Apr 27, 2009 2:44 pm Post subject: |
|
|
Hi plusminus,
Any idea how can i save a portion of image into a file. Eg: 480x320 image i want to cut into say 4 pieces and save to different files, based on a coordinate in the picture.
Thank you for any help.
SMN |
|
| Back to top |
|
 |
tripmills Freshman

Joined: 02 May 2009 Posts: 5
|
Posted: Sat May 02, 2009 3:10 pm Post subject: any help? |
|
|
Thanks for this great stuff. I am not new to programming (about 30yrs), but i have always stayed away from java up until now.
i would kill for some help to my little problem and i bet it is a simple solution that i just cant see/grasp right now.
here is my issue:
i wrote a game and i want it to save the highscore. i have a thread within a view extended from the main activity. The closest i got to success was to create another class extended from the main activity but everytime i reference it from the thread/view i force close.
any thoughts would be helpful - thanks. |
|
| Back to top |
|
 |
marcelloma Junior Developer

Joined: 18 Mar 2009 Posts: 12
|
Posted: Thu May 07, 2009 9:53 pm Post subject: Re: any help? |
|
|
| tripmills wrote: | Thanks for this great stuff. I am not new to programming (about 30yrs), but i have always stayed away from java up until now.
i would kill for some help to my little problem and i bet it is a simple solution that i just cant see/grasp right now.
here is my issue:
i wrote a game and i want it to save the highscore. i have a thread within a view extended from the main activity. The closest i got to success was to create another class extended from the main activity but everytime i reference it from the thread/view i force close.
any thoughts would be helpful - thanks. |
Have you tried saving it on a file? Or using the Bundle object? |
|
| Back to top |
|
 |
|
|
 |
tnagarajan Freshman

Joined: 30 Sep 2009 Posts: 2
|
Posted: Wed Sep 30, 2009 5:33 pm Post subject: |
|
|
Hello Experts,
Can anybody please tell me, how to write and read a text file outside the application path.
And also how can i include this, while packaging.
Regards,
Nagarajan T. |
|
| Back to top |
|
 |
afzkl Freshman

Joined: 01 Oct 2009 Posts: 2
|
Posted: Fri Oct 02, 2009 3:35 pm Post subject: |
|
|
| Java: | // ##### Read the file back in #####
/* We have to use the openFileInput()-method
* the ActivityContext provides.
* Again for security reasons with
* openFileInput(...) */
FileInputStream fIn = openFileInput("samplefile.txt");
InputStreamReader isr = new InputStreamReader(fIn);
/* Prepare a char-Array that will
* hold the chars we read back in. */
char[] inputBuffer = new char[TESTSTRING.length()];
// Fill the Buffer with data from the file
isr.read(inputBuffer);
// Transform the chars to a String
String readString = new String(inputBuffer);
// Check if we read back the same chars that we had written out
boolean isTheSame = TESTSTRING.equals(readString);
// WOHOO lets Celebrate =)
Log.i("File Reading stuff", "success = " + isTheSame);
} catch (IOException ioe) {
ioe.printStackTrace();
} |
char[] inputBuffer = new char[TESTSTRING.length()];
Thanks works great but I have one small issue. How should I know how big the inputBuffer char array should be if i don't know the length of the textfile? |
|
| Back to top |
|
 |
sandeepz Once Poster

Joined: 21 Nov 2009 Posts: 1
|
Posted: Sat Nov 21, 2009 1:31 am Post subject: uses-permission for writing on sdcard |
|
|
Also note that, need to add permission in AndroidManifest.xml for writing files on sdcard:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> |
|
| Back to top |
|
 |
laksmi07 Freshman

Joined: 26 Nov 2009 Posts: 2
|
Posted: Thu Nov 26, 2009 10:17 am Post subject: Writing userdefined objects to a file |
|
|
Hi I am a novice in android.
I want to write user defined objects to a file. Is it possible to do it with files or it has to be done using input output streams. RIM has persisantstorage for saving objects while for j2me its a round about work still we have rms. What is the option other than sqlite?
Thanks
Lakshmi |
|
| Back to top |
|
 |
rogerdodger Junior Developer

Joined: 30 Nov 2009 Posts: 15
|
Posted: Mon Nov 30, 2009 8:45 am Post subject: Packge PNG File |
|
|
I am new to android development....
Can someone please explain how to package a PNG (for example wallpaper.png) in my package? I've been searching everywhere and can't figure this out.
When I add it to my package in Eclipse /src/com.my_package/files/wallpaper.png it doesn't exist on the device emulator.
I'm trying to set it to the system wallpaper, but i keep getting FileNotFound exception /data/data/com.my_package/files/wallpaper.png
So how can i package a PNG file in my package so that i can open it?
Here is how i am trying to open it
| Java: |
try {
in = openFileInput("wallpaper.png");
mWallpaperManager.setStream(in);
success = true;
}
|
|
|
| Back to top |
|
 |
Johan Degraeve Developer

Joined: 27 Oct 2009 Posts: 40 Location: Belgium
|
Posted: Mon Nov 30, 2009 9:30 am Post subject: Re: Packge PNG File |
|
|
| rogerdodger wrote: | I am new to android development....
Can someone please explain how to package a PNG (for example wallpaper.png) in my package? I've been searching everywhere and can't figure this out.
|
you need to put your file in your res/drawable folder , see
resources
The id to use in this method, this you can find in your R class, which is automatically generated by Eclipse, as soon as you add your source file to your res folder _________________ regards,
Johan |
|
| Back to top |
|
 |
rahulsak Freshman

Joined: 10 Feb 2010 Posts: 2
|
Posted: Tue Mar 02, 2010 10:48 am Post subject: |
|
|
hello,
I am a beginner in android.
I want to know hw to create xml file from program.
Actually i want to collect data from GUI and store that data to new xml file.
plz give me some solution to this.
Thanks in Advance!!  |
|
| Back to top |
|
 |
|