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. How to download Android codes under a firewall blocking the default GIT port

[How to download Android codes under a firewall blocking the default
GIT port]

Although there are some web sites to post something similar to this
HOW-TO, my post seems to be more effective than any others, at least
to the three people: me and two anonymous persons who used the tip to
solve their downloading problem quickly. So I just like to drop this
tip on this mailing list for sharing.

http://lazyswamp.blogspot.com/2010/11/git-firewalls-and-android-source-codes.html

Kwanghoon

-- 

2. Clickable ImageView with custom selector

Hello,

In my application I need an ImageView that is clickable and that shows
its selected state to the user.
It should also be longClickable.

My problem is that I when I set my ImageView clickable, my
onClickListener is no longer called. And when I don't  set my
ImageView clickable, my selected state is not visible.

Anyone has some tips on how to accomplish this?

-- 

3. Android opengl app

4. How to use Android documentation ?

5. Trying to get my head around multi screen densities. With more info

6. Backlight is blinking.

7. Trying to get my head around multi screen densities.