0

I have a class that calls a BroadcastReceiver. I am struggling to delete a file when it's called.

If I use deleteFile("file.txt") within the class it works and deletes the file.

However if I try deleteFile("file.txt") within the BroadcastReceiver class it won't work.

Any ideas on how I can delete a file within a BroadcastReceiver class? I have tried many different ways and I an guessing there is something fundamental I'm missing.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

deleteFile() is a method on Context. While Activity and Service inherit from Context, BroadcastReceiver does not.

Instead, call deleteFile() on the Context passed into onReceive().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491