Android Question Text file, Intent to edit, and DIRInternal - oh my

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I have the following little snippet of code:
B4X:
Sub mniWLst_Click
  Dim fn As String
  Dim nt As Intent

  fn = "file://" & File.Combine(apVals.dir, apVals.wfile)
  nt.Initialize(nt.ACTION_EDIT, fn)
  nt.SetType("text/plain")
  StartActivity(nt)
End Sub

I want to open a text file in the default editor.

AppVals.dir is either File.DirDefExternal or File.DirInternal if the device has no SD card.

This code works as intended using DirDefExternal, but fails when DirInternal is used. The error message displayed by the chosen text editor program is "File Load Error" or "please insert SD card" depending on the editor chosen.

In both cases, DirDefExternal and DirInternal, fn looks correct and the file is loaded and used within the program using the same location.

I am guessing the error has something to do with directory privileges - DirInternal cannot be accessed by the text editing program.

Am I guessing correctly? Is there a way around this?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks.

There is no DirDefExternal available. During initialization I test File.Exists(File.DirDefExternal, ""). If this equals false (no SD card), I choose DirInternal. On a phone with no SD card, is there no world read/write location? Should I be choosing a different File.Dir... location if I want apps storage that is world read/write enabled?

Barry.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
...During initialization I test File.Exists(File.DirDefExternal, ""). ..
If you mean that when you first run the app the system return FALSE then it is correct, you have to COPY it first, now, if you are testing if a SDCard is present or not then is a different issue, but then again, DirInternal is only accessible by your app if a device lacks an SDCard then your app should not run, besides, nowadays to find a device without an SDCard is very rare.
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
... besides, nowadays to find a device without an SDCard is very rare.

Thanks, yes I test for the SD card's presence at startup.

You are right that these phones are rare. I just happen to have one that I use to test compatibility with Android 2.3. I think I will just ignore the error since it will likely never be encountered anyway.

Barry.
 
Upvote 0
Top