Android Question Problems with ContentChooser

driesvp

Member
Licensed User
Longtime User
I've seen on the forum that some people are facing problems with contentChooser, me too! Nevertheless I followed the advices, I'm still facing the same problem: every now and then the imgChooser_result routine is triggered. What else can cause this problem?
I don't receive an error nor I can't see any entry in the logs

B4X:
Sub Process_Globals
    Dim ImageChooser As ContentChooser
   
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("detail")
   
    ImageChooser.Initialize("imgChooser")
End Sub

B4X:
Sub btnOpladen_Click
   
    ImageChooser.show("image/*", "Choose image")

End Sub

Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)
    Dim FileNM As String
    Dim j As HttpJob
    Dim out As OutputStream

    If Success Then
        ToastMessageShow("Foto geupload",False)
    End If
End Sub
 

driesvp

Member
Licensed User
Longtime User
I don't completely understand the answer, I made this service module, but it doesn't work.

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim ImageChooser As ContentChooser
    Dim nb As Notification
  
End Sub
Sub Service_Create
    nb.Initialize
    nb.Icon=""
    nb.OnGoingEvent = True
    nb.DefaultVibrate=False
    nb.Notify(1)
    ImageChooser.Initialize("imgChooser")
    Service.StartForeground(1, nb)
  
End Sub

Sub Service_Start (StartingIntent As Intent)
    ImageChooser.show("image/*", "Choose image")
  
End Sub

Sub Service_Destroy

End Sub

Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)
    Dim FileNM As String
    Dim j As HttpJob
    Dim out As OutputStream

    If Success Then
        ToastMessageShow("Foto geupload",False)
    End If

End Sub
 
Upvote 0

ldb68

Member
Licensed User
Longtime User
It's working, thanks!
A clarification.
If I want to use "ContentChooser" in my app I have to create the app as a service and before the cc.show call Service.StartForeground?
It is not necessary to create a service that must be called by the app?

thanks
 
Upvote 0

ldb68

Member
Licensed User
Longtime User
Please start a new thread for this question.
I'm sorry to bore.
I did not want to open another post just like this.
My question on preventing errors in the use of the CC was the same.
Unfortunately I did not clear the answer
"Have you created a service and called Service.StartForeground?"
and how to implement it in my app where I use the CC to select a file that i need to upload to a web service

PS:
your response here is more clear. I try it
https://www.b4x.com/android/forum/threads/content-chooser.33165/#post-194162
>The problem is that the OS kills your app process while its in the background.
>You should add a service to your app, start it and call Service.StartForeground.
>This will prevent the OS from killing the process.
>You only need to call Service.StartForeground before using ContentChooser and then you can call Service.StopForeground.

thanks
 
Last edited:
Upvote 0
Top