Frage

I'm trying get my app to get the name of every app on the device. The best way I can think of doing this is reading the name of every directory in /data/data/ into a list. I have the following code which works on other directories but not /data/data/.

public void generateDirList() {
        File rootDir = new File(currentLocation);
        String[] directories = rootDir.list();
        subDirs = new ArrayList<String>();

        for(String dir : directories)
        {
            if (new File(currentLocation + File.separator + dir).isDirectory())
            {
                Log.i(TAG, dir);
                subDirs.add(dir);
            }
        }
    }

The problem seems to be that /data isn't being recognized as a directory so rootDir.list() returns null. My device is rooted and I have the following in my manifest

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

What else do I have to do to get this to work ?

War es hilfreich?

Lösung

I'm trying get my app to get the name of every app on the device

Use PackageManager and methods like getInstalledApplications().

The problem seems to be that /data isn't being recognized as a directory so rootDir.list() returns null.

No, the problem is that you do not have read access to /data.

I have the following in my manifest

There is no such permission defined in Android.

What else do I have to do to get this to work ?

I presume that you can use su to run ls -R or something like that. I suggest that you use PackageManager.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top