Jul 20, 2021 Replies: 35 This is a B4i and B4A example, which demonstrates various external files related tasks. The behavior is not exactly the same as the platforms capabilities and behavior are different. B4A Load external files, including online files, using ContentChooser. Save to an external target, using SaveAs: https://www.b4x.com/android/forum/t...list-of-other-related-methods.129897/#content Allow other apps to view text files using this app : Receiving shared images from other apps Extract information from the passed uri. Note that no permission is needed. The minimum version was set to 7 (API 24), though it will probably work in older versions as well. Don't miss the manifest editor additions and ime in the main module. B4i Load external files, including online files, using DocumentPickerViewController: https://www.b4x.com/android/forum/t...ments-with-documentpickerviewcontroller.99365 Share the text with ActivityViewController: https://www.b4x.com/android/forum/t...pp-with-activityviewcontroller.73159/#content This also allows saving the text with the Files app. Allow other apps to view text files using this app: https://www.b4x.com/android/forum/threads/open-external-files-with-your-app.50525/#content Don't miss the main module PListExtra attributes and OpenUrl event. A bit related B4J example: https://www.b4x.com/android/forum/threads/class-recent-files-manager.104633/post-822842 Updates: - 9/2023 - Fixed an issue in B4A where overwriting existing files didn't trim file. Thanks @noeleon for reporting! Attachments TextEditor.zip TextEditor.zip 184.2 KB · Views: 3,149 Last edited: Sep 10, 2023 Click to expand...
This is a B4i and B4A example, which demonstrates various external files related tasks. The behavior is not exactly the same as the platforms capabilities and behavior are different. B4A Load external files, including online files, using ContentChooser. Save to an external target, using SaveAs: https://www.b4x.com/android/forum/t...list-of-other-related-methods.129897/#content Allow other apps to view text files using this app : Receiving shared images from other apps Extract information from the passed uri. Note that no permission is needed. The minimum version was set to 7 (API 24), though it will probably work in older versions as well. Don't miss the manifest editor additions and ime in the main module. B4i Load external files, including online files, using DocumentPickerViewController: https://www.b4x.com/android/forum/t...ments-with-documentpickerviewcontroller.99365 Share the text with ActivityViewController: https://www.b4x.com/android/forum/t...pp-with-activityviewcontroller.73159/#content This also allows saving the text with the Files app. Allow other apps to view text files using this app: https://www.b4x.com/android/forum/threads/open-external-files-with-your-app.50525/#content Don't miss the main module PListExtra attributes and OpenUrl event. A bit related B4J example: https://www.b4x.com/android/forum/threads/class-recent-files-manager.104633/post-822842 Updates: - 9/2023 - Fixed an issue in B4A where overwriting existing files didn't trim file. Thanks @noeleon for reporting!
Roger Daley Well-Known Member Licensed User Longtime User Jul 22, 2021 #2 Erel, great example and possibly what I need. A couple of dumb questions. [Due to health issues I've done F.A. on B4A for ages, so the questions are probably dumber than usual.] I have a couple of Apps [not in B4X Pages] that create their own folder in the root directory and use this folder as an import/export location between App and user. With the ongoing changes for access to secondary/external memory I have become completely confused as to where we stand and what is coming. Sometime ago a notice from Google appeared to state that Apps requesting access to this memory would be removed from Playstore in May so I nobbled those Apps to avoid this. This did not happen. 1. Currently this texteditor can read/write to the SD Card. Will this still work when Google make it's forecast changes to memory access? 2. Is there a way for the App to check/create a folder on the SD Card? Regards Roger Last edited: Sep 13, 2021
Erel, great example and possibly what I need. A couple of dumb questions. [Due to health issues I've done F.A. on B4A for ages, so the questions are probably dumber than usual.] I have a couple of Apps [not in B4X Pages] that create their own folder in the root directory and use this folder as an import/export location between App and user. With the ongoing changes for access to secondary/external memory I have become completely confused as to where we stand and what is coming. Sometime ago a notice from Google appeared to state that Apps requesting access to this memory would be removed from Playstore in May so I nobbled those Apps to avoid this. This did not happen. 1. Currently this texteditor can read/write to the SD Card. Will this still work when Google make it's forecast changes to memory access? 2. Is there a way for the App to check/create a folder on the SD Card? Regards Roger
Erel B4X founder Staff member Licensed User Longtime User Jul 22, 2021 #3 1. Yes. It follows Google recommendations. 2. With this approach you are letting the user choose whichever folder they like so it is not really relevant to create a folder. Your program cannot directly create a folder with the "SaveAs" approach.
1. Yes. It follows Google recommendations. 2. With this approach you are letting the user choose whichever folder they like so it is not really relevant to create a folder. Your program cannot directly create a folder with the "SaveAs" approach.
Roger Daley Well-Known Member Licensed User Longtime User Jul 22, 2021 #4 Erel said: 1. Yes. It follows Google recommendations. 2. With this approach you are letting the user choose whichever folder they like so it is not really relevant to create a folder. Your program cannot directly create a folder with the "SaveAs" approach. Click to expand... Thanks Erel, I guess I'm starting with a blank page and two lot's of code. One in pages one not. It will come together eventually. The next bit will be dealing with the data in a database and getting a html help file from assets to the real world. That's for another day. ?? Many thanks Roger
Erel said: 1. Yes. It follows Google recommendations. 2. With this approach you are letting the user choose whichever folder they like so it is not really relevant to create a folder. Your program cannot directly create a folder with the "SaveAs" approach. Click to expand... Thanks Erel, I guess I'm starting with a blank page and two lot's of code. One in pages one not. It will come together eventually. The next bit will be dealing with the data in a database and getting a html help file from assets to the real world. That's for another day. ?? Many thanks Roger
Roger Daley Well-Known Member Licensed User Longtime User Aug 1, 2021 #6 Hi All, Trying to save using name of existing file. If I type in the file name and SAVE, the file is saved with the addition of (1). EG FileX.txt becomes FileX.txt(1) . Leaving the original in place If I click on FileX.txt in the file list this become the file name. When I click SAVE a pop-up queries if it should overwrite the existing file. How can I change to always query overwriting existing files? Regards Roger
Hi All, Trying to save using name of existing file. If I type in the file name and SAVE, the file is saved with the addition of (1). EG FileX.txt becomes FileX.txt(1) . Leaving the original in place If I click on FileX.txt in the file list this become the file name. When I click SAVE a pop-up queries if it should overwrite the existing file. How can I change to always query overwriting existing files? Regards Roger
Roger Daley Well-Known Member Licensed User Longtime User Aug 1, 2021 #7 Hi All, In the SAVE/FILE LIST is it possible to edit colours, background, text etc. Regards Roger
M Mahares Expert Licensed User Longtime User Aug 1, 2021 #8 Roger Daley said: n the SAVE/FILE LIST is it possible to edit colours, background, text etc Click to expand... Roger, This is how I did it in the B4XPage_created Code: txtField.mBase.Color=xui.Color_Cyan txtField.TextField.TextColor=xui.Color_Red
Roger Daley said: n the SAVE/FILE LIST is it possible to edit colours, background, text etc Click to expand... Roger, This is how I did it in the B4XPage_created Code: txtField.mBase.Color=xui.Color_Cyan txtField.TextField.TextColor=xui.Color_Red
M Mahares Expert Licensed User Longtime User Aug 1, 2021 #9 Roger Daley said: How can I change to always query overwriting existing files? Click to expand... If you want to overwrite the file, simply when it prompts you with the newfile.txt, scroll down the screen to locate the original file and click it. It will ask you if you want to overwrite, click yes to preserve the original name.
Roger Daley said: How can I change to always query overwriting existing files? Click to expand... If you want to overwrite the file, simply when it prompts you with the newfile.txt, scroll down the screen to locate the original file and click it. It will ask you if you want to overwrite, click yes to preserve the original name.
Roger Daley Well-Known Member Licensed User Longtime User Aug 2, 2021 #10 Mahares said: Roger, This is how I did it in the B4XPage_created Code: txtField.mBase.Color=xui.Color_Cyan txtField.TextField.TextColor=xui.Color_Red Click to expand... Thanks Mahares but it is the SAVE/FILES screen I am after. I don't know the proper name so I have attached a screenshot Regards Roger.
Mahares said: Roger, This is how I did it in the B4XPage_created Code: txtField.mBase.Color=xui.Color_Cyan txtField.TextField.TextColor=xui.Color_Red Click to expand... Thanks Mahares but it is the SAVE/FILES screen I am after. I don't know the proper name so I have attached a screenshot Regards Roger.
Erel B4X founder Staff member Licensed User Longtime User Aug 2, 2021 #11 You don't have any control on this screen. It is a system screen which is not part of your app.
Roger Daley Well-Known Member Licensed User Longtime User Aug 2, 2021 #12 Mahares said: If you want to overwrite the file, simply when it prompts you with the newfile.txt, scroll down the screen to locate the original file and click it. It will ask you if you want to overwrite, click yes to preserve the original name. Click to expand... Thanks again Mahares but I want to avoid relying on the user checking to make sure that the file name does not already exist. If a user SavesAs FileX.txt and does not see that FileX.txt already exists they get FileX.txtx(1). Surprisingly some users see this as a problem. Regards Roger
Mahares said: If you want to overwrite the file, simply when it prompts you with the newfile.txt, scroll down the screen to locate the original file and click it. It will ask you if you want to overwrite, click yes to preserve the original name. Click to expand... Thanks again Mahares but I want to avoid relying on the user checking to make sure that the file name does not already exist. If a user SavesAs FileX.txt and does not see that FileX.txt already exists they get FileX.txtx(1). Surprisingly some users see this as a problem. Regards Roger
Roger Daley Well-Known Member Licensed User Longtime User Aug 2, 2021 #13 Erel said: You don't have any control on this screen. It is a system screen which is not part of your app. Click to expand... Thanks Erel.
Erel said: You don't have any control on this screen. It is a system screen which is not part of your app. Click to expand... Thanks Erel.
Erel B4X founder Staff member Licensed User Longtime User Oct 13, 2022 #14 B4A code that handles the intent when a text file is being opened from a different app was missing. Code: Private Sub B4XPage_Appear #if B4A HandleLoadResult(FileHandler1.CheckForReceivedFiles) #end if End Sub Fixed.
B4A code that handles the intent when a text file is being opened from a different app was missing. Code: Private Sub B4XPage_Appear #if B4A HandleLoadResult(FileHandler1.CheckForReceivedFiles) #end if End Sub Fixed.
jahswant Well-Known Member Licensed User Longtime User Oct 22, 2022 #15 Is project example missing here or I'm missimg something !
Erel B4X founder Staff member Licensed User Longtime User Oct 23, 2022 #16 Yes. Not sure what happened. I've uploaded it to the first post.
jahswant Well-Known Member Licensed User Longtime User Oct 23, 2022 #17 Erel said: I've uploaded it to the first post. Click to expand... Thanks. I thought I was going crazy !
Erel said: I've uploaded it to the first post. Click to expand... Thanks. I thought I was going crazy !
LucaMs Expert Licensed User Longtime User Feb 28, 2023 #18 Since this is the thread and example reference for file handling, load and save, I used this to allow the user to select and play an audio file. I just changed the MIME type in the Sub Load: B4X: cc.Show("audio/*", "Choose audio file") Although it seems to work fine, this is the contents of the LoadResult: B4X: Wait For (FileHandler1.LoadAudioFile) Complete (Result As LoadResult) If Result.Success Then Log("DIR: " & Result.Dir) Log("FN : " & Result.FileName) Log("RN : " & Result.RealName) End If DIR: ContentDir FN : content://com.android.providers.media.documents/document/audio%3A2247 RN : Dream_It_Possible.flac I cannot use MediaPlayer passing those values to it, of course. Last edited: Feb 28, 2023
Since this is the thread and example reference for file handling, load and save, I used this to allow the user to select and play an audio file. I just changed the MIME type in the Sub Load: B4X: cc.Show("audio/*", "Choose audio file") Although it seems to work fine, this is the contents of the LoadResult: B4X: Wait For (FileHandler1.LoadAudioFile) Complete (Result As LoadResult) If Result.Success Then Log("DIR: " & Result.Dir) Log("FN : " & Result.FileName) Log("RN : " & Result.RealName) End If DIR: ContentDir FN : content://com.android.providers.media.documents/document/audio%3A2247 RN : Dream_It_Possible.flac I cannot use MediaPlayer passing those values to it, of course.
Erel B4X founder Staff member Licensed User Longtime User Feb 28, 2023 #19 LucaMs said: I cannot use MediaPlayer passing those values to it, of course. Click to expand... Try it. It should work.
LucaMs said: I cannot use MediaPlayer passing those values to it, of course. Click to expand... Try it. It should work.
LucaMs Expert Licensed User Longtime User Feb 28, 2023 #20 Erel said: Try it. It should work. Click to expand... Done (now); it crashes.