Pecurka Pecurka - 1 year ago 79
Android Question

How to find files in a folder that name starts with a specific String in Android

Can someone help me...

I am making an Android app and i need now to search for files in Download folder of my device and if i find files that name starts with

then call a function.


Answer Source

Something like this should work:

File dir = Environment
File[] files = dir.listFiles();

for (File file : files) {
    if (file.getName().startsWith("data")) {
        // call your function

Don't forget to add the READ_EXTERNAL_STORAGE permission to your manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Since the protectionLevel of this permission is dangerous, on API level 23+ you need to request this permission at runtime. Check out the corresponding developer's guide article.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download