Android Question Using FileHandler for geoJson File

Davisbc

Member
Licensed User
The following is the code for selecting a geoJson file (i assume):

B4X:
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/geo+json", "Choose geoJson file")

the geo+json came from the android documentation.

When i go to select the file, it will not let me select a geojson file. The list that comes up says that the geoJson file is a BIN file. It will identify the json as JSON, but not a geoJson file.

If i change the code to:

B4X:
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/*", "Choose geoJson file")

and add .txt as the extension as in abc.geojson.txt, it will allow me to select the file and process. I understand why this works, the json/geojson not being recognized and selected is the issue.

i have added a geoJson test file generated by https://geojson.io/ to help.

Thanks
B
 

Attachments

  • demo.zip
    1.7 KB · Views: 10

Davisbc

Member
Licensed User
Manifest for above

B4X:
'Receive files
AddActivityText(Main,
<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.OPENABLE" />
   <data android:mimeType="text/*" />
   '<data android:mimeType="application/json" />
</intent-filter>)
 
Upvote 0

teddybear

Well-Known Member
Licensed User
The following is the code for selecting a geoJson file (i assume):

B4X:
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/geo+json", "Choose geoJson file")

the geo+json came from the android documentation.

When i go to select the file, it will not let me select a geojson file. The list that comes up says that the geoJson file is a BIN file. It will identify the json as JSON, but not a geoJson file.

If i change the code to:

B4X:
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/*", "Choose geoJson file")

and add .txt as the extension as in abc.geojson.txt, it will allow me to select the file and process. I understand why this works, the json/geojson not being recognized and selected is the issue.

i have added a geoJson test file generated by https://geojson.io/ to help.

Thanks
B
The MIME type should be "application/geo+json" instead of "text/geo+json"
B4X:
cc.Show("application/geo+json", "Choose geojson file")
 
Upvote 0

Davisbc

Member
Licensed User
No, i had already tried that, but i tried it again. geo+json will not load geojson or json.

Using application/json will load json but not geoJson.

i also updated the mimeType in the mainfest to application/* as in:

B4X:
AddActivityText(Main,
<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.OPENABLE" />
   '<data android:mimeType="text/*" />
   <data android:mimeType="application/*" />
</intent-filter>)

the link with the type info is https://www.iana.org/assignments/media-types/application/geo+json

Thanks for trying,
B
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Did you try it with the TextEditor?
ezgif-60c4a22b05015db7.gif
 
Upvote 0

Davisbc

Member
Licensed User
Thanks,

i had used this app as an example when i started. I agree its great.

My app originally worked. However, i noticed the problem when i started testing after i upgraded to b4a 13.7

Using B4a 13.7, i get the same result for the text editor as my program. The text editor uses

B4X:
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("text/*", "Choose text file")

which is where i started. The only thing i did notice is that i am using core(libr) 13.5 and the latest is 13.7

i don't know if its related, but i will update that libr and retry.

contentResolver is version 1.5, i will check if there is an update

B
 
Upvote 0

Davisbc

Member
Licensed User
i read it wrong, i am already using the latest version of Core. i am using version 13.7

Surprised to see the online version is 13.5

Probably not updated online.

B
 
Upvote 0

Davisbc

Member
Licensed User
Changed the code to

B4X:
    Dim cc As ContentChooser
    cc.Initialize("cc")
    'cc.Show("application/json", "Choose geoJson file")
    cc.Show("*/*", "Choose geoJson file")
    Wait For cc_Result (Success As Boolean, Dir As String, FileName As String)

"*/*" allowed it to work.

Thanks,
B
 
Upvote 0
Top