【问题标题】:Unable to access Android content provider无法访问 Android 内容提供程序
【发布时间】:2013-05-14 16:30:33
【问题描述】:

我可以在 LogCat 中看到 ActivityManager 正在报告有关特定内容提供商的某些信息。我使用以下代码尝试访问该内容提供程序以了解更多信息:

    Cursor cursor = context.getContentResolver().query(uriDSDS, null, null, null, null); 

    String[] columnNames = cursor.getColumnNames();        
    Log.d(TAG, "columnNames=" + columnNames.toString());

不幸的是,在尝试获取光标后,我在 LogCat 中看到以下错误:

未能找到 __

的提供者

有什么问题?为什么我无法访问此提供程序?难道访问权限仅限于某些应用程序?有没有办法进入 ADB 或其他东西来查看设备上所有可用的内容提供者?

【问题讨论】:

  • 抱歉这个明显的问题,uriDSDS 是什么?
  • 这是我为看似“双卡”内容提供商创建的字符串。我在 logcat 中看到了字符串,所以我希望附加到它。有没有办法找出我设备上所有可用的内容提供程序,以便我可以检查字符串以确定我有正确的内容提供程序?
  • 我要查询的内容提供者的 URI。

标签: android android-contentprovider


【解决方案1】:

确保添加正确的 Uri 例如

Uri uriDSDS = Uri.parse( “内容://aaa.aaa/values”);

【讨论】:

  • 有什么方法可以验证您的 Uri 是否正确?您可以查询提供商并以某种方式查看它提供的所有内容吗?
【解决方案2】:

如以下工作示例所示,请检查您的 uriDSDS 是否正确。

Cursor people = getContentResolver().query(
                        ContactsContract.Contacts.CONTENT_URI, null, null, null,
                        null);

                // get contact id
                while (people.moveToNext()) {
                    if (people != null) {
                        int numberFieldColumnIndex = people
                                .getColumnIndex(PhoneLookup._ID);
                        String number = people.getString(numberFieldColumnIndex);
                        contactId.add(number);
                    }
                }

                people.close();

【讨论】:

  • 如何验证我的 URI 是否正确?有没有办法在给定设备上浏览所有内容提供者?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多