Android Question How to load a csv file using contentchooser

saeed10051

Active Member
Licensed User
Longtime User
Hi All
I am using following code to select a csv file located in my mobile to, the code is opening the selection window and csv file shows there but it is greyed out and cannot be selected. Is there some problem with MIME in this case or some other issue

Code: Copy
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim CC As ContentChooser 'Phone Library
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private ButtonGetImage As Button
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    
    Activity.LoadLayout("Layout1")

    CC.Initialize("CC")
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ButtonGetImage_Click
    
   CC.Show("csv/*", "Choose csv")
End Sub

Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim su As StringUtils
    Dim Table As List
    
    
    If Success = True Then
        Table = su.LoadCSV(Dir, FileName, ",")
       
    Else
        ToastMessageShow("No Success :(",True)
    End If
    Log(Table.Get(0))   
End Sub
 
but it is greyed out and cannot be selected
the mime does not match or there is no content provider for this mime type.

Try "text/csv"
 
Upvote 0
Earlier i had this csv file in DirAsset and it was opening fine, but in that case i had to package this file with my app, i want to keep this file on my mobile in some folder and pick if from there when the app is launcher so that if i make changes to the file and next time when i open the app, it loads updated file. Is there a way to do it directly other than content chooser??
 
Upvote 0
Earlier i was using following code
B4X: Copy
Table = su.LoadCSV(File.DirAssets, "test.csv", ",")
The file is located in internal storage/documents
should i write su.LoadCSV(/documents, "test.csv",",") to load directly, also this way the location of the file will be hard coded in the app
 
Upvote 0
Hi Mahares, i am getting following error when i am trying to run the file. The file name is restaurant.csv. I have placed the csv file in the Documents folder
java.io.FileNotFoundException: /data/user/0/b4a.example/files/Documents/restaurant.csv: open failed: ENOENT (No such file or directory)
 
Upvote 0
i have used following thread
and found that the MIME for csv file is application/vnd.ms-excel. however when i run if using file chooser it is selecting the csv file but not showing the content inside the file. do i need runtime permission for that
 
Upvote 0
whole thing working like a charm now. Thanks to all of you for your help and special thanks for Erel for content chooser uri app.
B4X: Copy
CC.Show("application/vnd.ms-excel/*", "Choose csv")
above code is being used to select csv file. Also i am not using any runtime permissions over here.
 
Upvote 0
Back
Top