0

What I have in mind is pretty simple. I want to write a small script for simple file managing, and I would like for it to be run automatically like once a day. I have some coding experience under my belt so the actual implementation won't really be a problem. What I'm actually confused about is if the Android platform has any features that would make executing the routines viable.

The bulk of the coding I do day-to-day is Python, but I could get used to Java or Kotlin's syntax in a couple days if necessary, and from there its just really simple logic. Considering that Android is really just Linux at the core, I imagine it would be possible to have it run a couple lines of code automatically everyday at a set time, as I have done on my linux machine a couple of times.

I'm pretty much a complete newbie when it comes to fiddling with Android's workings, so if anyone has done anything like what I'm attempting or knows about relevant documentation, some guidance would be much appreciated.

3
  • 1
    While Android is built on the Linux kernel, Android != Linux due to additional frameworks & restrictions on non-rooted device. Rooted gives you more options. You should explicitly describe what "simple file management" you are thinking of, what version of Android, hardware model, and if the device is rooted or not. Aug 30 '20 at 19:17
  • So, what I would like the script to do is to look through a predetermined folder and check for any files older than like, 3 or so days, and delete said files. Would be nice if it executed once a day. With a regular linux distro, I could get that to work by writing to my bash profile, I don't know if that's possible on Android. As for the device, it's running android version 9, kernel 4.9.117+, unrooted. Aug 30 '20 at 19:32
  • 1
    Android itself provides neither any cron-like mechanism, nor a terminal login (so no .profile/.bashrc etc. (related details)). You can use AlarmManager API in your app for repeated tasks. Or use some automation app. Or with root: How to run an executable on boot and keep it running?. Also related: android.stackexchange.com/a/221420/218526 Aug 30 '20 at 22:10
0

No

On a non-rooted device, files are generally considered private to apps (think each app as a userid and you don't have sudo). Apps and their data are meant to be isolated from each other in the increasingly privacy focused mobile world.

As you have programming experience, here is the Android Developer documentation on data storage and you will note the different types such as media and "documents" using the Storage Access Framework. Add on Adoptable Storage for SD cards and you get experienced non-Android developers asking questions like What's the current status of Internal vs External vs Removable vs Adoptable Storage on Android?. Regardless, if your "predetermined folder" is a system one, without root you won't have access either.

The above SO question link to blog posts by Commonsware regarding the Android storage situation: internal storage, external storage, and removable storage as viewed from a developer perspective. Writing an app to interact with all of these storage types would be off-topic here in Android Enthusiasts but reading them gives context on how not like command line/shell Linux that Android has been and is becoming.

1
  • Thank you, the documentation will be more than helpful. I've been looking around for a way to keep my script running in the background. I imagine Android has some sort of 'bashrc' equivalent or something? Aug 30 '20 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.