Android Question How to Cause Instant B4xtable-Album Synchronization Update

omo

Active Member
Licensed User
Longtime User
I want when image or video is recorded or any other file, then send CallSub to update b4xtable instantly by syncronize new file in the folder instead of restarting the app before changes is made.

'i tried code below, but no effect:

CallSub (Main,"updateb4xtable")

B4X:
Sub updateb4xtable
    B4XTable1.UpdateTableCounters
    B4XTable1.Refresh
End Sub
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I take it that you want to update the data shown in your app if, for instance, a photograph is taken by the camera or if any image is added to phone storage. I asked ChatGPT how an Android app could receive a notification when one of these events happened. Apparently there are three things that you might try - File Observer, Media Scanner Notifications and Content Observers for Media Store - but all of these are problematic. I could not find any recent posts related to these options in this forum but you might have better luck.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Maybe you are asking why your updateB4xtable subroutine does not work. If so it would be useful to see how updated data is being received by your app and added to the B4XTable dataset.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
I take it that you want to update the data shown in your app if, for instance, a photograph is taken by the camera or if any image is added to phone storage. I asked ChatGPT how an Android app could receive a notification when one of these events happened. Apparently there are three things that you might try - File Observer, Media Scanner Notifications and Content Observers for Media Store - but all of these are problematic. I could not find any recent posts related to these options in this forum but you might have better luc

I take it that you want to update the data shown in your app if, for instance, a photograph is taken by the camera or if any image is added to phone storage. I asked ChatGPT how an Android app could receive a notification when one of these events happened. Apparently there are three things that you might try - File Observer, Media Scanner Notifications and Content Observers for Media Store - but all of these are problematic. I could not find any recent posts related to these options in this forum but you might have better luck.
Thank you Brian, you partially got it. I don't need notification. I want to update the data shown in B4Xtable-Album instantly in my app if a photograph is taken by the camera or if any image is added to phone storage or if video is recorded or other files is added to phone storage, I want it to instantly show in B4Xtable-Album without first exiting app before the added files show up in b4xtable.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Maybe you are asking why your updateB4xtable subroutine does not work. If so it would be useful to see how updated data is being received by your app and added to the B4XTable dataset.
Just like you said if a photograph is taken by the camera or if video is recorded via cam2x or if any image or video is added to phone storage. I want the file to quickly show up in B4Xtable-Album without first exiting app before update is made. I am not with my computer at moment to copy essential code here, but I used normal camera and cam2x for taking photo or record video and file chooser to select image or video. Immediately the video finished recording or camera finishes photo taken, I used the callsub in #1 to called updateb4xtable, but no changes
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I think that I understand now. Your app uses a B4XTable to list media files. It also uses camera functions to create new media files. When it creates a new file you want the newly created file to be added to the B4XTable list. This seems perfectly sensible, so if it is not working then maybe there is an error in your coding. You need to show us more code - so far you have shown only four lines.

Of course, saving and retrieving the new media files could mean accessing external storage which might be where the problem lies. We must wait and see.

Edit : I have been thinking - maybe I still have this wrong. Maybe you just need to refresh your table when your app returns to the foreground in case a new media file has been created while it was in the background. But the situation is still the same: you need to show us more code.
 
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
I think that I understand now. Your app uses a B4XTable to list media files. It also uses camera functions to create new media files. When it creates a new file you want the newly created file to be added to the B4XTable list. This seems perfectly sensible, so if it is not working then maybe there is an error in your coding. You need to show us more code - so far you have shown only four lines.

Of course, saving and retrieving the new media files could mean accessing external storage which might be where the problem lies. We must wait and see.

Edit : I have been thinking - maybe I still have this wrong. Maybe you just need to refresh your table when your app returns to the foreground in case a new media file has been created while it was in the background. But the situation is still the same: you need to show us more code.
Thank you so much Brian; sorry, I didn't respond so fast as I wanted. I will look again at the code by God's grace tomorrow today to give another attempt as you suggested. However, there is no special code except one record video with camera or take picture with camera or cam2x. Video and pictures were successfully taken and stored in the subfolder of dirinternal. All I want now is for b4xtable to update itself once I sent b4xtable1.refresh or b4xtable1.updatecounter
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
May be this
ex:
B4XTable1.Refresh
Wait For B4XTable1_DataUpdated
@zed, thank you so much. Sorry, I didn't see your message on time. I will give it a trial later today to see what difference it will make. Thanks
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Maybe now I understand (at last). You simply want to know how to update and display data in a B4XTable - the data involved and where it comes from is not part of the question, and "instant synchronisation" is not an issue.

There are other similar questions in the forum so you are not the first person to have this problem but I cannot find a clear answer. The post here seems to be as good as any. It includes this code snippet . . .
B4X:
Sub SetValue (tbl As B4XTable, RowId As Long,value As String)
    tbl.sql1.ExecNonQuery2($"UPDATE data SET ${column.SQLID} = ? WHERE rowid = ?"$, Array As String(value, RowId))
    'updates the specific cell data
    B4XTable1.Refresh
End Sub

I cannot help you more myself unless I write a test app which I do not have time to do. I still think that it would be easier to help you if you posted more code, including the code that changes the database.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Maybe now I understand (at last). You simply want to know how to update and display data in a B4XTable - the data involved and where it comes from is not part of the question, and "instant synchronisation" is not an issue.

There are other similar questions in the forum so you are not the first person to have this problem but I cannot find a clear answer. The post here seems to be as good as any. It includes this code snippet . . .
B4X:
Sub SetValue (tbl As B4XTable, RowId As Long,value As String)
    tbl.sql1.ExecNonQuery2($"UPDATE data SET ${column.SQLID} = ? WHERE rowid = ?"$, Array As String(value, RowId))
    'updates the specific cell data
    B4XTable1.Refresh
End Sub

I cannot help you more myself unless I write a test app which I do not have time to do. I still think that it would be easier to help you if you posted more code, including the code that changes the database.
@Brian Dean , thank you. My description is not a database driven, it is just B4XTable - Photos Album update of list of video, audio files from dirinternal subfolder
 
Upvote 0
Top