Is there a way to list column names in an undocumented but allowed ContentProvider in Android?

你。 提交于 2019-12-10 20:22:24

问题


Suppose that you have AbcContentProvider which allows you to query/update it with it's content:// url.

Is it possible to see the names/values those can be updated or queried?

(This would be similar to "select * from table_abc" in an sql query or like "Show tables" from a database table)


回答1:


This will help:

Uri u = // your CONTENT_URI
Cursor c = context.getContentResolver(uri, null, null, null, null, null);
Log.d(TAG, "listing column for uri=" + uri);
for (int i = 0; i<c.getColumnCount(); i++) {
    Log.d(TAG, "column " + i + "=" + c.getColumnName(i));
}

If the remote ContentProvider is not accepting a null projection:

  1. If this is about an android internal ContentProvider: Read the android source code: http://source.android.com/
  2. If this is about some other app: Decompile it and read the source code: Android - How to decode and decompile any APK file?
  3. You can brute force the list by querying with single element projection with a list of (random/generated) names



回答2:


have you read Cursor docs? if not: getColumnCount() & getColumnName(idx)



来源:https://stackoverflow.com/questions/18672806/is-there-a-way-to-list-column-names-in-an-undocumented-but-allowed-contentprovid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!