Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Need help writing to external Android directories

Author
Message
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 29th Sep 2019 19:53 Edited at: 30th Sep 2019 01:45
Tested the following code in Windows and it works.
It does the desired task of copying "myalarm.wav" from the /media folder of the app to the "C:\Alarms" folder.

I can't for the life of me figure out how to get it to work saving to the /Alarms folder on an Android device.
NOTE: I am not talking about /system/media/audio/alarms but the non-system "/Alarms" folder you can access through most file explorers and a USB transfer connection.


I have tried the below code the following ways:

- AppGameKit player with "raw:/Alarms/myalarm.wav"
- manually installed APK with "raw:/Alarms/myalarm.wav"
- AppGameKit player with "/Alarms/myalarm.wav"
- manually installed APK with "/Alarms/myalarm.wav"

Screenshot of error message in all cases is attached.



Both AppGameKit Player and the manual install were given storage write permissions. I know AGk writes stuff to really strange places at times (ex: users/username/appdata/srslybro?/whyhideithere?) so I am at a bit of a loss as to how to even begin troubleshooting writing to external directories on Android.


Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 29th Sep 2019 20:00
Android hides its directory structure from applications, for security so as a result I don't think you can write
to just anywhere. The write commands will work if you don't use raw think of it like a safety box where android places
things
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
AliceSim1
5
Years of Service
User Offline
Joined: 15th Oct 2018
Location: Barcelona
Posted: 29th Sep 2019 20:37
you must first check, request and verify that you have access to external storage, it is a basic permit.
Without first checking that permission it is impossible for you to read, create, delete files on Android.

Look helps docs:
https://www.appgamekit.com/documentation/Reference/Extras/RequestPermission.htm

https://www.appgamekit.com/documentation/Reference/Extras/CheckPermission.htm
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 30th Sep 2019 01:05
Anyone familiar with this that can point me in the right direction here?




"Android hides its directory structure from applications, for security so as a result I don't think you can write to just anywhere"

"NOTE: I am not talking about /system/media/audio/alarms but the non-system "/Alarms" folder you can access through most file explorers and a USB transfer connection."

-------------------------------------------------------------------------

"you must first check, request and verify that you have access to external storage, it is a basic permit. Without first checking that permission it is impossible for you to read, create, delete files on Android."

"Both AppGameKit Player and the manual install were given storage write permissions."


-------------------------------------------------------------------------

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Sep 2019 09:53 Edited at: 30th Sep 2019 09:54
This post has been marked by the post author as the answer.
Alicesim is correct.

1) You need to request write permission first with the commands listed above.
2) When you do have write permission, you then need to use the "raw:" text before the full file path.
3) Any file access using raw needs a FULL file path. Not a partial one
4) Android is case sensitive with filepaths and filenames so you need to be careful with lower case

Typically on android the directory will start something like /storage/emulated/0/ (- its not like windows)
The path should also exist rather then you trying to create it.

IF you do it all right - then yes you can write a file
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 1st Oct 2019 03:01 Edited at: 1st Oct 2019 03:42

1) You need to request write permission first with the commands listed above.

That code from the link is in the program. I had only posted the part of the code doing the task.

2) When you do have write permission, you then need to use the "raw:" text before the full file path.

Correct. I listed that in the first post.

3) Any file access using raw needs a FULL file path. Not a partial one

That is my question. Figuring out what that right file path is has proven difficult. There seems to be about a dozen different variations on how Android phones do it.

4) Android is case sensitive with filepaths and filenames so you need to be careful with lower case

Correct. The case as presented in my initial post is how it is done in the test phones I have (Alcatel, LG815, and Galaxy J3)


"IF you do it all right - then yes you can write a file"
Agreed. The code works under Windows, so finding the 'right' path for the Android phones is my hurdle here.


EDIT: "Typically on android the directory will start something like /storage/emulated/0/ " <--- it was exactly that. THANK YOU! Every search I did was giving me /sdcard, /Internal storage, and a host of other paths.

That was the piece I needed. Thank you, very much!
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 1st Oct 2019 12:55
Yeah, thats why i suggested to look at the path and suggested that particular path starting at /storage in my post

Login to post a reply

Server time is: 2024-04-24 01:50:07
Your offset time is: 2024-04-24 01:50:07