SharedPreferences has the method getAll() that returns a Map<String, ?> . From the Map you can retrieve easily the keys with keySet() and the key/value mappings with entrySet():
Although @Blackbelt's answer is quite popular here, I think it is not actually targeting the question. (It is not suprising since the question mixes up the terminology of preferences names and keys.) I guess the question is how to find out which shared preferences instances have been created - which can be of interest if the names are created dynamically.
Here are two strategies for that:
create another shared preferences "meta" instance where all created shared prefences instances are registered by adding a key/value pair for it to the meta prefs - with the key being the shared prefences name and the value being any value e.g. true.
To obtain all shared prefences created by you, use the meta prefs and follow the answer of @Blackbelt.
shared preferences have a backup file, which is stored in folder /data/data/YOUR_PACKAGE_NAME/shared_prefs with name YOUR_PREFS_NAME.xml
So you can look into that directory for your shared preferences files. But be careful, there might be shared preferences files that were not created by your logic! Therfore I would stick with the first approach.
After reading @Delacrix response and playing with the Kotlin-way (tested in Kotlin 1.3.11) of retrieving the keys, I found out an even shorter version for getting the keys (or even the values):
val prefsA = context.getSharedPreferences("MyAttack", Context.MODE_PRIVATE)
val prefsAIDs = sharedPreferences.all.keys //returns MutableSet<String>
The same way, you can access only the values via sharedPreferences.all.values (even tho is not what you asked in your question, might be a useful for other readers).