2

I am running my android app on the Blackberry Playbook using RIM's eclipse plugin.

Files I create in the "/accounts/1000/shared/documents" directory are "locked" (when I browse to them and try open using the AIR browser, I get the error message "file locked"). Files that I create in the "/sdcard" directory (the one returned by Environment.getExternalStorage) work fine. I can create and read these files programatically using the below code.

Any suggestions on how to create files in the documents directory which are not "locked"?

public class TempActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        try
        {
            File docFile = new File("/accounts/1000/shared/documents/tmp.txt");
            File sdcardFile = new File(Environment.getExternalStorageDirectory().getPath() + "/tmp.txt");

            FileWriter writer = new FileWriter(docFile);

            try
            {
                writer.write("Hello doc file");
                Log.i("success writing doc file", "success writing doc file");
            }
            catch (Exception e)
            {
                Log.e("exception writing doc file", Log.getStackTraceString(e));
            }

            writer.close();
            writer = new FileWriter(sdcardFile);

            try
            {
                writer.write("Hello sdcard file");

                Log.i("success writing sdcard file", "success writing sdcard file");
            }
            catch (Exception e)
            {
                Log.e("exception writing sdcard file", Log.getStackTraceString(e));
            }

            writer.close();
            FileReader in = new FileReader(docFile);
            BufferedReader reader = new BufferedReader(in);

            try
            {
                Log.i("firstLine in doc file", reader.readLine());
            }
            catch (Exception e)
            {
                Log.e("exception reading doc file", Log.getStackTraceString(e));
            }

            in.close();
            reader.close();
            in = new FileReader(sdcardFile);
            reader = new BufferedReader(in);

            try
            {
                Log.i("firstLine in sdcard file", reader.readLine());
            }
            catch (Exception e)
            {
                Log.e("exception reading sdcard file", Log.getStackTraceString(e));
            }

            in.close();
            reader.close();
        }
        catch (Exception e)
        {
            Log.e("exception", Log.getStackTraceString(e));
        }

    }
}
ab11
  • 19,770
  • 42
  • 120
  • 207

1 Answers1

1

Take a look at this thread regarding files on the Playbook and Android.

http://supportforums.blackberry.com/t5/BlackBerry-Plug-in-for-Android/How-to-save-files-to-shared-directory/m-p/1401369/highlight/true#M454

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
  • thanks, but the problem they discuss is obtaining permissions to write to this directory (they were unable to write at all). I am able to write to the directory, but the file is not written in a way that os likes. It gives error message "file locked" when I try to open the txt file, and the file does not show up in windows explorer when I connect the device to my pc by usb. – ab11 Mar 20 '12 at 17:10
  • And this is after you've exited the android app? (by exited I mean killed) – Morrison Chang Mar 20 '12 at 17:41
  • yes, happens even after i restart the device. (happens with the text files created by the simple sample app in my question above) – ab11 Mar 20 '12 at 17:46
  • I'm leaning toward that this is a use case that the Playbook Android 'sandbox' had not anticipated. Since you are accessing Playbook directories and not the SD card mount point your app wouldn't work on a 'normal' Android device. This is sort of implied by the 'Linux virtual file systems (/proc and /sys will not be supported at the app level)' on the API support page. https://bdsc.webapps.blackberry.com/android/apisupport – Morrison Chang Mar 20 '12 at 17:50
  • i am confused though because these files can be later accessed programtically from the android sandbox, but don't behave properly from other contexts (can't open using playbook file browser, not visible in windows explorer) – ab11 Mar 20 '12 at 18:47
  • My guess is that its incomplete so it partially works, only Blackberry can answer for sure. – Morrison Chang Mar 20 '12 at 18:56
  • thanks, I posted on their support forums and eagerly anticipate their reply – ab11 Mar 20 '12 at 18:59