Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - getFilesDir() not working (red in Android Studio)

Tags:

android

Im trying to write a class that saves images on disk.

Inside class I have method public static String saveToSdCard(Bitmap bitmap, String filename) and inside it I try to get a reference to files folder by using File path = new File(getFilesDir(), "myfolder");but I cant because IDE marks it red.

What am I doing wrong ?

like image 582
Alexey K Avatar asked Oct 26 '25 15:10

Alexey K


1 Answers

You have to call it on the context. Make sure you are in an Activity, or otherwise call it on a context instance, like getActivity().getFilesDir() or context.getFilesDir(), or even view.getContext().getFilesDir().

like image 169
Daniel Zolnai Avatar answered Oct 29 '25 04:10

Daniel Zolnai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!