Pergunta

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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top