Android: How to get a file's creation date?

get file name from uri android
get file from uri android
how to get the path of selected pdf/doc from file manager in android programmatically
android get file from content uri
how to get file path in android studio
get file path from uri android
android get pdf file path from content uri
android open file from path

This is my code:

File TempFiles = new File(Tempfilepath);
if (TempFiles.exists()) {
    String[] child = TempFiles.list();
    for (int i = 0; i < child.length; i++) {
        Log.i("File: " + child[i] + " creation date ?");
        // how to get file creation date..?
    }
}

The file creation date is not an available, but you can get the last-modified date:

File file = new File(filePath);
Date lastModDate = new Date(file.lastModified());
Log.i("File last modified @ : "+ lastModDate.toString());

Retrieving file information, To get the data type of a shared file given its content URI, the client app calls ContentResolver.getType() . This method returns the file's MIME type  How to Access Android’s Built-In File Manager. If you’re using a device with stock Android 6.x (Marshmallow) or newer, there’s a built-in file manager…it’s just hidden away in the Settings. Head to Settings > Storage > Other and you’ll have a full list of all the files and folders on your internal storage.

Here's how I would do it

// Used to examplify deletion of files more than 1 month old
// Note the L that tells the compiler to interpret the number as a Long
final int MAXFILEAGE = 2678400000L; // 1 month in milliseconds

// Get file handle to the directory. In this case the application files dir
File dir = new File(getFilesDir().toString());

// Obtain list of files in the directory. 
// listFiles() returns a list of File objects to each file found.
File[] files = dir.listFiles();

// Loop through all files
for (File f : files ) {

   // Get the last modified date. Milliseconds since 1970
   Long lastmodified = f.lastModified();

   // Do stuff here to deal with the file.. 
   // For instance delete files older than 1 month
   if(lastmodified+MAXFILEAGE<System.currentTimeMillis()) {
      f.delete();
   }
}

File, It worked for me !!! Hope It works for u.. private Uri imageUri; public void onClick(​View arg0) { switch (arg0.getId()) { case R.id.btnImageCapture: Intent intent  Assets and resources are files on your development machine. They are not files on the device. For assets, use open() on AssetManager to get an InputStream on your asset.

The file creation date is not an available piece of data exposed by the Java File class. I recommend you rethink what you are doing and change your plan so you will not need it.

Open files using storage access framework, ' although sometimes this folder is in another folder called 'Samsung' located in the app drawer. You can also search your phone via Settings > Application Manager > All Applications. Open APK Extractor. It's a green app with a white Android robot on it. The APK Extractor app will allow you to save an app's APK file to your Android's memory, at which point you can share the file.

Starting in API level 26, you can do this:

File file = ...;
BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
long createdAt = attr.creationTime().toMillis();

Android - Get file with path, , so it's best to leave them where they are. Android phones can't open every file type by default, but there are ways to open and play all files types on Android. In this article, we'll show you how.

There is an alternate way. When you open the file for the first time save the lastModified date, before you modify the folder.

long createdDate =new File(filePath).lastModified();

And then when you close the file do

File file =new File(filePath);
file.setLastModified(createdDate);

If you have done this since the file was created, then you will have the createdDate as the lastModified date all the time.

How do I find apps I have downloaded?, manipulation operations such as cut, copy, delete, share, etc. If you are on Android 6.0+ (API Level 23+) you have to explicitly ask for permission to access external storage. Simply having <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> in your manifest won't be enough. You also have actively request the permission in your activity:

NOMEDIA File - What is it and how do I open it?, Transfer files between your computer & Android device Files: Learn how to upload files and folders to Google Drive. Option 2: Move files with a USB cable To get the latest tips, tricks, and how-to's, subscribe to our YouTube Channel. Yes. First, construct a File representing the image path: File file = new File(a); If you're starting from a relative path: file = new File(file.getAbsolutePath()); Then, get the parent: String dir = file.getParent(); Or, if you want the directory as a File object, File dirAsFile = file.getParentFile();

Managing Files on Android: 7 Essential Tips You Need to Know, Android's user-visible file system is one of its advantages over iOS. It allows you to more easily work with files, opening them in any app of your  Transfer files between your computer & Android device You can use your Google Account or a USB cable to move photos, music, and other files between your computer and phone. Important: Some of these steps work only on Android 9 and up.

Transfer files between your computer & Android device, By far the easiest way to find downloaded files on Android is to look in your app drawer for an app called Files or My Files. Google's Pixel  Android file transfer: How to move data between your phone and computer Moving files between your Android device and a Windows PC, Mac, or Chromebook doesn't have to be difficult — or dependent

Comments
  • If you wanted create time why you accepted modified time ? stackoverflow.com/questions/2723838/…
  • use last-modified HTTP header.
  • As @CommonsWare points out below the lastModified time is not the creation time. The creation time is not available.
  • please read first, use of last-modified is an option cause the creation time is not available.
  • One bit of information I miss is a clear specification of whether File.lastModified is local time or UTC. The consensus is that it is UTC stackoverflow.com/questions/5264339/… and that's also what I'd expect in a semi-modern system. But why don't Oracle's specs developer.android.com/reference/java/io/… clearly state this? "... measured in milliseconds since January 1st, 1970, midnight." can, if one is sufficiently paranoid, be interpreted as either UTC January 1st, 1970, midnight, or local January 1st, 1970, midnight.
  • It is stored in milliseconds since UTC Jan 1st, 1970, but you don't have to worry about that - it is the standard definition of "epoch". Anything Date displays for you can be displayed in local time or UTC time or any time zone.
  • +1 I like this answer the best. I ran this in a thread and it worked pretty well. Also, love the var name MAX_FILEAGE :P
  • You're not answering the question. This is the file last modified date.
  • This is wrong. File supports this, developer.android.com/reference/java/io/…
  • @Fuzzy: That is the last-modified time. It is not the file creation time once the file has been modified.
  • you've saved some of us lots time
  • yeah, but have to wait 3-4 years until devices with API below 26 become rarely used
  • @user924: Depends on your use case. If you're writing an app for yourself, or a controlled environment (small team), you could do this today. Good to know about.
  • I didn't know that Android is such a junk.
  • Interesting idea, though it only works if your app created the file.