adam2evans
adam2evans

Reputation: 3

Deleting a file from BroadcastReceiver

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.

Upvotes: 0

Views: 253

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006819

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().

Upvotes: 1

Related Questions