" SQLiteException:没有这样的列:MIME类型"在Android中使用ContactsContract时 [英] "SQLiteException: no such column: mimetype" when using ContactsContract in Android

本文介绍了" SQLiteException:没有这样的列:MIME类型"在Android中使用ContactsContract时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要删除Android的内部数据库表中的条目 ContactsContract ,即应该从联系人条目中删除的事件,如生日。

以下code工作pretty很好,但有些用户(约1%),这已经与的SQLException 崩溃。那么,有什么问题我code或只是他们的设备不支持Android的 ContactsContract 是否正确?

  {尝试
    ArrayList的<龙> rawContactIDs = getRawContactID(o.getID());
    INT rawContactCount = rawContactIDs.size();
    对于(INT R = 0;为r rawContactCount; R ++){
        长rawContactID = rawContactIDs.get(R);
        字符串,其中= ContactsContract.Data.MIMETYPE += AND+ ContactsContract.Data.RAW_CONTACT_ID += AND+ ContactsContract.CommonDataKinds.Event.TYPE +=;
        的String []选择=新的String [] {ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,将String.valueOf(MY_RAW_CONTACT_ID),将String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)};
        。getContentResolver()删除(ContactsContract.Data.CONTENT_URI,其中,选择);
    }
}
赶上(例外五){}

时引发的例外是:

  android.database.sqlite.SQLiteException:没有这样的列:MIME类型:,而
编译:DELETE FROM WHERE数据MIME类型=?和raw_contact_id =?和
数据2 =?

android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)

android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)

android.content.ContentProviderProxy.delete(ContentProviderNative.java:472)
在android.content.ContentResolver.delete(ContentResolver.java:700)
在... ... MY_ACTIVITY


解决方案

这是可能的设备制造商更改的ContentProvider 的实施附带的AOSP。从理论上讲,这些变化将通过兼容性测试套件(CTS)被捕获,因此,只有通过Play商店发货时不破API将运行你的应用程序的设备。

话虽这么说...


  • 的CTS还远远没有完成

  • 的CTS不保护你,如果你故意散布您的应用程序超越Play商店,有人用不兼容的设备上运行你的应用程序

  • 的CTS不保护你,如果你的无意的不兼容的设备分发您的应用程序之外的Play商店(即您的应用被盗版),有人运行你的应用程序

  • 各种设备制造商海盗Play商店应用程序本身

所以,当你看到这似乎从内部发起问题操作系统提供的的ContentProvider ,但这些问题是罕见和/或正在无法识别的设备,不要惊慌。你还可以选择以某种方式在这种情况下正常失败(通过包裹在自己的异常处理程序失败的调用),但它不太可能,你的code是真正的困难之源。

I want to delete an entry from Android's internal database table ContactsContract, i.e. an event such as a birthday should be removed from the contact's entry.

The following code works pretty well, but some users (ca. 1%) have this crashing with an SQLException. So is there anything wrong in my code or is it just that their device doesn't support Android's ContactsContract correctly?

try {
    ArrayList<Long> rawContactIDs = getRawContactID(o.getID());
    int rawContactCount = rawContactIDs.size();
    for (int r = 0; r < rawContactCount; r++) {
        long rawContactID = rawContactIDs.get(r);
        String where = ContactsContract.Data.MIMETYPE+" = ? AND "+ContactsContract.Data.RAW_CONTACT_ID+" = ? AND "+ContactsContract.CommonDataKinds.Event.TYPE+" = ?";
        String[] selection = new String[] { ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE, String.valueOf(MY_RAW_CONTACT_ID), String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY) };
        getContentResolver().delete(ContactsContract.Data.CONTENT_URI, where, selection);
    }
}
catch (Exception e) {}

The exception that is thrown is:

android.database.sqlite.SQLiteException: no such column: mimetype: , while
compiling: DELETE FROM data WHERE mimetype = ? AND raw_contact_id = ? AND
data2 = ?
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at
android.content.ContentProviderProxy.delete(ContentProviderNative.java:472)
at android.content.ContentResolver.delete(ContentResolver.java:700)
at ... MY_ACTIVITY ...

解决方案

It is possible for device manufacturers to change the implementation of a ContentProvider that ships with the AOSP. In theory, those changes would be caught by the Compatibility Test Suite (CTS), so that only devices that don't break the API will run your app when shipped through the Play Store.

That being said...

  • The CTS is far from complete
  • The CTS does not protect you if you intentionally distribute your app beyond the Play Store, and somebody with an incompatible device runs your app
  • The CTS does not protect you if you unintentionally distribute your app beyond the Play Store (i.e., your app's been pirated), and somebody with an incompatible device runs your app
  • Various device manufacturers pirate the Play Store app itself

So, when you see problems that would appear to originate from within an OS-supplied ContentProvider, but those problems are infrequent and/or are on unrecognized devices, don't panic. You still might choose to somehow fail gracefully in this case (by wrapping the failing calls in your own exception handler), but it's unlikely that your code is really the source of the difficulty.

这篇关于&QUOT; SQLiteException:没有这样的列:MIME类型&QUOT;在Android中使用ContactsContract时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆