android deleting a file from internal storage

I have created a file stored on internal storage from an activity. How can I delete this file from another activity?

I’m thinking I’ll have to get the file’s directory (which I’m not sure how to) and delete it. I tried using

  • How to send parameters from a notification-click to an activity?
  • Android app doens't call “onDestroy()” when killed (ICS)
  • Why is the soft keyboard being hidden on resume?
  • Set LayoutDirection (RTL) for api lower than 17
  • Get URI from drawable image
  • Understanding RecyclerView setHasFixedSize
  • context.deleteFile(); 

    but it won’t work because I’m trying to call it from a non-static method.

    Any help is appreciated.

    Related posts:

    Android DrawerLayout doesn't show the right indicator icon
    Android Keystore getEntry() and generateKeyPair() throw Exceptions sometimes
    Unexplained gap/padding to the left, between Toolbar, and LinearLayout
    Referencing an XML string in an XML Array (Android)
    Android AudioTrack buffering problems
    Context wants FLAG_ACTIVITY_NEW_TASK but I've already set that flag
  • load Bitmap with RGB_565 via Picasso
  • The import cannot be resolved
  • Android - Return to calling Activity
  • Android multiple databases open
  • Android - Proguard duplicate zip entry error
  • FloatingActionButton hide on list scroll
  • 3 Solutions collect form web for “android deleting a file from internal storage”

    Here is your answer :

    File dir = getFilesDir();
    File file = new File(dir, "my_filename");
    boolean deleted = file.delete();

    You can try getting the instance pointing to the file and deleting it like in
    this answer
    or this one

    For non-rooted mobile context.deleteFile();-like instructions work well for current application.

    File dir = getFilesDir();
    File file = new File(dir, "my_filename");
    boolean deleted = file.delete(); 

    work well for rooted mobiles.

    Please help if anyone has code that will delete files from non-rooted phones.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.