【问题标题】:Why is this getting "Failed to get type for: content://contacts/"为什么会出现“无法获取类型:content://contacts/”
【发布时间】:2012-10-06 19:08:17
【问题描述】:

我正在逐步完成“专业 Android 4 应用程序开发”中的教程。在第 5 章中,有一个简单的应用程序演示了选择联系人并打印结果。

进入应用测试后,出现如下错误:

10-06 11:29:04.596: W/ContentResolver(1073): 无法获取类型: content://contacts/ (URI: content://contacts/, 调用用户: android.uid.system: 1000,调用包是以下之一:[com.android.keychain, com.android.settings, android, com.android.providers.settings, com.android.inputdevices])

此字符串在以下方法中被引用:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact_picker_tester);

    Button  button  = (Button) findViewById(R.id.pick_contact_button);

    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent  intent  = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/"));
            startActivityForResult(intent, PICK_CONTACT);
        }
    });
}

我想也许我做错了什么,所以我从Book source code 运行了相应的示例并得到了同样的错误。有什么想法可能有什么问题吗?

【问题讨论】:

    标签: android android-contacts android-contentresolver


    【解决方案1】:

    尝试改变

    Intent  intent  = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/"));
    

    到:

    Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    

    我认为你的 uri 不正确,这就是它抛出类型错误的原因。

    【讨论】:

      【解决方案2】:

      我刚刚浏览了这本书中的相同示例。内容 URI“content://contacts”无效并且缺少 authority。它应该被定义为

      Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://picker/contacts/"));
      

      权限“picker”是整个提供者的任意名称。

      【讨论】:

        【解决方案3】:

        您的 android manifest.xml 中是否有正确的权限?

        你需要:

        android.permission.READ_CONTACTS
        

        来自http://developer.android.com/reference/android/Manifest.permission.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-18
          • 2014-05-18
          • 2020-01-12
          相关资源
          最近更新 更多