0

Firstly I get an ArrayList using the method getFilePaths. method { List out all images from SD card.}

How to continue?

At phone, when you see details over image, you can see:

tittle, hour, width, height, orientation, fileSize, path...

I want get all attributes/details/properties of a file jpg and save them in variables.

I tried do this: Properties Class Java but I think that's not the right way

Community
  • 1
  • 1
  • Maybe this helps you http://stackoverflow.com/questions/12623302/get-meta-data-of-image-android Properties Class from Java is used to manage .properties file in order to organize your app configuration, not to get file properties – Joe Hackerberg Feb 22 '17 at 13:06
  • 1
    "Firstly I get an ArrayList using the method getFilePaths. method { List out all images from SD card.}" -- that code has nothing to do with an SD card and is inefficient. "you can see: tittle, hour, width, height, orientation, fileSize, path" -- those are pieces of metadata that [come from the `MediaStore`](https://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns.html). If you query the `MediaStore` for images, not only will you get that data, but it should run faster than your "scan the entire external storage area for images" approach. – CommonsWare Feb 22 '17 at 13:15
  • ty commonsware, i going to try it. However, i need know how to get all images from a directory, (whatsapp images in my case) – vicente maldonado Feb 22 '17 at 17:59

2 Answers2

0

You can retrieve Properties from File like below code add your file into below code and get Properties object

  Properties prop = new Properties();
            // load a properties file
            prop.load(input);

private void retrievePropertiesFromFile(){
        String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root + "/CHETAN");
        String fname = "mytext.txt";
        File myFile = new File (myDir, fname);

        InputStream input = null;
        try {
        input = new FileInputStream(myFile);
        Properties prop = new Properties();
        // load a properties file
        prop.load(input);
        // get the property value and print it out
         Log.i(getClass().getSimpleName(),prop.getProperty("text"));
         Log.i(getClass().getSimpleName(),prop.getProperty("textstyle"));
         Log.i(getClass().getSimpleName(),prop.getProperty("typeface"));
         Log.i(getClass().getSimpleName(),prop.getProperty("typeface"));
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43
0

Ok, I using this simple code and it show null in property text:

File imageJPG = new File("/storage/emulated/0/WhatsApp/Media/WhatsApp Images","6gMRtQyY.jpg");

        if(imageJPG.isFile()){
            System.out.println("its file");
            System.out.println("image: "+imageJPG);
        }else{
            System.out.println("no");
        }

        InputStream input = null;
        try {
            input = new FileInputStream(imageJPG);
            Properties prop = new Properties();
            prop.load(input);
            // get the property value and print it out
            System.out.println("property text: "+prop.getProperty("text"));
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

Console: 

I/System.out: its file
I/System.out: image: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/6gMRtQyY.jpg
I/System.out: property text: null