Problem with Saving and opening file on moto-droid

by Andr茅 » Tue, 04 May 2010 04:40:52 GMT


Sponsored Links
 Hello,

I have an app that can read and write txt files to the phones sdcard.
By using this code for reading files:

        @Override
        protected void onListItemClick(ListView l, View v, int position, long
id) {
                super.onListItemClick(l, v, position, id);
                mFileNameOpen = files.get(position);
                String st = null;
                mVector.clear();
                notepad.mNewEmpty = false;
                try {
                        File f = new 
File(Environment.getExternalStorageDirectory()+"/
notepad/"+mFileNameOpen);
                        FileInputStream fileIS = new FileInputStream(f);
                        BufferedReader in = new BufferedReader(new
InputStreamReader(fileIS));
                        do {
                                st = in.readLine();
                                mVector.add(st);
                        }while(st!=null);
                        in.close();

                        ...

                } catch (FileNotFoundException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }

        }

and this to write them:

              try {
                        File root = Environment.getExternalStorageDirectory();
                        File fileCheck = new File(root, "/notepad/" + 
fileNameSave +
saveExtension);
                    boolean exists = fileCheck.exists();
                    if (!exists) {
                        if (root.canWrite()) {
                                        File textFile = new File(root, 
"/notepad/" + fileNameSave +
saveExtension);
                                        FileWriter textWriter = new 
FileWriter(textFile);
                                        BufferedWriter out = new 
BufferedWriter(textWriter);
                                        out.write(SAVEAS);
                                        out.close();
                                        written = true;
                                } else {
                                        written = false;
                                }
                    } else {
                        written = true;
                        showMaybe = 1;
                        showDialog(DIALOG_SAVE_EXISTS);
                    }
                } catch (IOException e) {
                        Log.v(getString(R.string.app_name), e.getMessage());
                }

This has been working fine on my Tattoo and all the emulators I've
tried this on. But it does not seem to be working on moto droid. Is
there something different to consider with moto droid? Or have I
missed something in the manifest maybe?

Any suggestions?

--



Problem with Saving and opening file on moto-droid

by TreKing » Tue, 04 May 2010 04:49:01 GMT


 




Define "it does not seem to be working on moto droid".

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


Problem with Saving and opening file on moto-droid

by Andr茅 » Tue, 04 May 2010 05:50:22 GMT


 Sorry, it force closes on reading in a file. And can't write to sdcard
on write.






>



Problem with Saving and opening file on moto-droid

by Andr茅 » Tue, 04 May 2010 16:35:06 GMT


 No one knows why this could be?

This is all the information I have since I don't own a moto droid
myself. I only got this from 5 different comments in the android
market. Has any one experienced this before?







> >



Problem with Saving and opening file on moto-droid

by TreKing » Tue, 04 May 2010 23:02:43 GMT


 



I assume you have the EXTERNAL_STORAGE permission, of course?

Besides that, your best option is to get a stacktrace of the problem to see
exactly where you're going wrong. See if you can get a friendly user to help
you out or find someone you know with a Droid to test on.





If no one responded, apparently not ...

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--



Problem with Saving and opening file on moto-droid

by niko20 » Thu, 06 May 2010 05:04:21 GMT


 As mentioned, on Android 1.6 and up your app needs to declare the
WRITE_EXTERNAL_STORAGE permission in it's manifest file or all sdcard
write calls will fail.

-niko






>



Problem with Saving and opening file on moto-droid

by Andr茅 » Fri, 07 May 2010 00:50:01 GMT


 Thanks both of you for your answering. I'm waiting for a guy getting
back to me with a stacktrace of the problem.

I have declared the permission in the manifest file. Does it matter
where I declare it in the file?

The strange thing is that it works fine on some devices and not at all
on others. So far I have got reports of this problem on moto droid,
htc hero sprint and g1.

-Andr






> >



Problem with Saving and opening file on moto-droid

by TreKing » Fri, 07 May 2010 02:03:03 GMT


 



Well, yeah - you can't just put it anywhere. Maybe post that part of your
manifest to double check.

For example, mine looks like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
and it's a child of the root "manifest" node.

But I would expect the build process to throw an error if it were in the
wrong place. And it would fail miserably on all post 1.5 devices (and the
emulator, one would assume) if that were the case.



I don't know about the Hero, but if it's past 1.5, the permission seems like
a likely culprit.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--



Problem with Saving and opening file on moto-droid

by Andr茅 » Fri, 07 May 2010 03:26:42 GMT


 ere is the manifest. Where the line of stars are is where I think I
had the permission line first and I just moved it to the bottom.
Is this correct?


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="#####"
android:versionCode="2"
android:versionName="2.0.1">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
*********************************************************
<activity android:name=".#####" android:label="@string/
app_name" android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".#####" android:theme="@android:style/
Theme.NoTitleBar" android:windowSoftInputMode="stateVisible|
adjustResize" />
<activity android:name=".#####" android:theme="@android:style/
Theme.NoTitleBar" android:windowSoftInputMode="stateVisible|
adjustResize"/>
<activity android:name=".#####" android:theme="@android:style/
Theme.NoTitleBar" android:windowSoftInputMode="stateVisible|
adjustResize" />
<activity android:name=".#####" android:theme="@android:style/
Theme.NoTitleBar" android:windowSoftInputMode="stateVisible|
adjustResize" />
<activity android:name=".#####" android:theme="@android:style/
Theme.NoTitleBar" android:windowSoftInputMode="stateVisible|
adjustResize" />
<activity android:name=".#####" android:theme="@android:style/
Theme.NoTitleBar" android:windowSoftInputMode="stateVisible|
adjustResize" />
</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

On May 6, 8:02pm, TreKing <treking...@gmail.com> wrote:
>



Problem with Saving and opening file on moto-droid

by TreKing » Fri, 07 May 2010 03:54:48 GMT


 




Think so - that's how I have mine set up and it works just fine.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--



Problem with Saving and opening file on moto-droid

by Andr茅 » Fri, 07 May 2010 23:33:30 GMT


 That was the problem! I had the permissions line in the wrong place.
And then it apparently works on 1.6 phones but not phones with a newer
version of android!

-Andr






>



Other Threads

1. emulator: android_hw_control_init: hw-control qemud handler initialized

Hi,

I have customized the application in the gingerbread code & build the
image files(system.img, ramdisk.img etc). Now when I try to launch the
emulator created using the created system.img file, its unable to
boot. I see only  the black window with the "ANDROID" string, but I
can't see any desktop picture or any applications.

and the last output message is: emulator: android_hw_control_init: hw-
control qemud handler initialized.

If anyone know to resolve this issue, kindly let me know.

-- 

2. Serious problem on Android 2.3 and XmlSerializer

Hi all,

I am using the XmlSerializer to write XML to the sd-card. My code
works on all versions <= Android 2.2.
With the new Android 2.3 SDK and 2.3 Emulator I get an
NullpointerException:
Stacktrace:
java.lang.NullPointerException
at org.kxml2.io.KXmlSerializer.check(KXmlSerializer.java:75)
at org.kxml2.io.KXmlSerializer.text(KXmlSerializer.java:542)
...

Here is my code:
public class GPXWriter {
private XmlSerializer serializer;
private static final String NAMESPACE =null;
...
serializer.startTag(NAMESPACE , "test");
...
_serializer.endTag(NAMESPACE, "test");
...
}

I think the reason for the problem is the null-Namespace.
In the Javadoc of XmlSerializer(startTag) is written:" If namespace is
empty string then serializer will make sure that default empty
namespace is declared (in XML 1.0 xmlns='')"
-> null is in my opinion a correct value. If I use for example
NAMESPACE = "TEST" it works, but produces wrong xml.
There is a function "public abstract void setPrefix (String prefix,
String namespace)".
But calling this with "" as prefix like described in javadoc does not
fix the problem.
Here is the link to the javadoc
http://developer.android.com/reference/org/xmlpull/v1/XmlSerializer.html#startTag%28java.lang.String,%20java.lang.String%29

Does anyone know how to fix the problem?

-- 

3. Need help refresh different activity's when updating the database

4. how to render video YUV frame?

5. error in compiling GingerBread for Sholes

6. PORTING OF NEW OMX_CORE WITH STAGEFRIGHT

7. Mod: Paging ID-Android Jogja