Android ContentProvider 查找其他 URI

Android ContentProvider find other URIs

我正在编写一个将查询其他应用程序的 ContentProvider 的应用程序。我 运行 遇到了一个问题,因为在给定其 ProviderInfo 的情况下,我无法获取其他应用程序的 ContentProvider 的 URI。到目前为止,我有以下接受 ProviderInfo 对象的函数,但我不知道如何找到它的可用 URI 来查询。调用 provider.authority 是不够的,因为它没有指定要查询的后缀 table 名称。其他应用程序能够执行此操作,例如 ContentProviderHelper (https://github.com/jenzz/ContentProviderHelper),但我不太清楚它们是如何在代码中执行此操作的。

有人对此有好运吗?

public String[] getContentProviderColumnNames(ProviderInfo provider){
    Uri u = Uri.parse("content://"+provider.authority);//How do i get the complete URI?

    ContentResolver resolver = getActivity().getContentResolver();
    //below fails of course because the URI is invalid
    Cursor c = resolver.query(u, null, null, null, null);

    //Todo: for each found uri (tablename), query it using getColumnName
    //Get column names
    int colCount = c.getColumnCount();
    String[] columnNames = new String[colCount];
    for (int i = 0; i<colCount; i++) {
        columnNames[i] = c.getColumnName(i);
    }
    return columnNames;
}

谢谢

I am writing an application that will query other application's ContentProviders.

这不太可能奏效,因为您对其他应用程序的提供商一无所知。您可以通过这种方式访问​​的任何提供商都表明其他应用程序存在安全漏洞,因为提供商应该受到适当权限的保护。

I am running into a problem because I cannot get the other application's ContentProvider's URIs given its ProviderInfo.

正确。有效的 Uri 值取决于提供程序的实现,并且是不可发现的。

Other applications are able to do this, such as ContentProviderHelper (https://github.com/jenzz/ContentProviderHelper)

不,他们不是。 Driller 先生的搜索机制正在猜测 Uri 值,使用与问题中的代码片段相同的基本算法。没有要求提供商使用 Uri 值,我希望很少有人会这样做。其余为hard-coded