AggregationExceptions
java.lang.Object
android.provider.ContactsContract.AggregationExceptions
ClassOverview
Constantsforthecontactaggregationexceptionstable,
whichcontainsaggregationrulesoverridingthoseusedbyautomaticaggregation.
Thistypeonlysupportsqueryandupdate.Neitherinsertnordeletearesupported.
该类为用户提供了控制rawContact组不组成一个contactaggregation的方式。
<wbr style="line-height:25px">对于该表只能查询和更新。不能插入和删除。插入和删除都是由系统来控制的。</wbr><wbr style="line-height:25px"><br style="line-height:25px"> Columns<br style="line-height:25px"> AggregationExceptions<br style="line-height:25px"> intTYPEread/writeThetypeofexception:TYPE_KEEP_TOGETHER,TYPE_KEEP_SEPARATEorTYPE_AUTOMATIC.<br style="line-height:25px"> longRAW_CONTACT_ID1read/writeAreferencetothe_IDoftherawcontactthattheruleappliesto.<br style="line-height:25px"> longRAW_CONTACT_ID2read/writeAreferencetotheother_IDoftherawcontactthattheruleappliesto.<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">数据查询:</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">c=managedQuery(AggregationExceptions.CONTENT_URI,<br style="line-height:25px"> newString[]{AggregationExceptions.TYPE,AggregationExceptions.RAW_CONTACT_ID1,<br style="line-height:25px"> AggregationExceptions.RAW_CONTACT_ID2},<br style="line-height:25px"> null,null,null);</span><br style="line-height:25px"> 注意这里查询到的只是TYPE为TYPE_KEEP_TOGETHER和TYPE_KEEP_SEPARATE的项。<br style="line-height:25px"> 系统的意思就是在这里只是定义Exception的Aggregation规则。默认的为TYPE_AUTOMATIC,自然不在此表。想想如果TYPE_AUTOMATIC得要定义在表中的话,那这个表的数据量就太大了。而且对于TYPE_AUTOMATIC的关系没有必要再定义,不定义就是TYPE_AUTOMATIC。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">数据更新:</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> 需要注意的是对于想让一个集合的各元素的TYPE做改变时,最好对各个元素和其他的关系(TYPE)都做改变。<br style="line-height:25px"> 比如想让A,B,C变成一组。不应该简单的让A与B,A与C变成TYPE_KEEP_TOGETHER。<br style="line-height:25px"> 而应该让A与B,A与C,B与C都变成TYPE_KEEP_TOGETHER。<br style="line-height:25px"><span style="line-height:25px">例1</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">void</span><span style="color:#ff6600; line-height:25px">doAggregationAllByBatch()</span>{<br style="line-height:25px"><span style="color:#0000ff; line-height:25px">Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);</span><span style="color:#808080; line-height:25px">//注意这里的条件</span><br style="line-height:25px"><br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ArrayList<ContentProviderOperation>ops=newArrayList<ContentProviderOperation>();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"> ops.add(ContentProviderOperation.newUpdate(<br style="line-height:25px"> AggregationExceptions.CONTENT_URI).withValue(<br style="line-height:25px"> AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_TOGETHER).withValue(<br style="line-height:25px"> AggregationExceptions.RAW_CONTACT_ID1,rawContactId)<br style="line-height:25px"> .withValue(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2).build());<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> try{<br style="line-height:25px"> getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);<br style="line-height:25px"> }catch(Exceptione){<br style="line-height:25px"> e.printStackTrace();<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><span style="line-height:25px">例2</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">void</span><span style="color:#ff6600; line-height:25px">doAggregationAll</span>(){<br style="line-height:25px"> Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);<br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ContentValuesvalues=newContentValues();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"><br style="line-height:25px"> values.put(AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_TOGETHER);<br style="line-height:25px"> values.put(AggregationExceptions.RAW_CONTACT_ID1,rawContactId);<br style="line-height:25px"> values<br style="line-height:25px"> .put(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2);<br style="line-height:25px"> getContentResolver().update(AggregationExceptions.CONTENT_URI,<br style="line-height:25px"> values,null,null);<br style="line-height:25px"> values.clear();<br style="line-height:25px"> Log.i("hubin",rawContactId+"unlink"+rawContactId2);<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><span style="line-height:25px">例3</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">void</span><span style="color:#ff6600; line-height:25px">doUnAggregationAllByBatch</span>(){<br style="line-height:25px"> Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);<br style="line-height:25px"><br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ArrayList<ContentProviderOperation>ops=newArrayList<ContentProviderOperation>();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"> ops.add(ContentProviderOperation.newUpdate(<br style="line-height:25px"> AggregationExceptions.CONTENT_URI).withValue(<br style="line-height:25px"> AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_SEPARATE).withValue(<br style="line-height:25px"> AggregationExceptions.RAW_CONTACT_ID1,rawContactId)<br style="line-height:25px"> .withValue(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2).build());<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> try{<br style="line-height:25px"> getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);<br style="line-height:25px"> }catch(Exceptione){<br style="line-height:25px"> e.printStackTrace();<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><span style="line-height:25px">例4</span>:<br style="line-height:25px"> voiddoUnAggregationAll(){<br style="line-height:25px"> Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);<br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ContentValuesvalues=newContentValues();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"><br style="line-height:25px"> values.put(AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_SEPARATE);<br style="line-height:25px"> values.put(AggregationExceptions.RAW_CONTACT_ID1,rawContactId);<br style="line-height:25px"> values<br style="line-height:25px"> .put(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2);<br style="line-height:25px"> getContentResolver().update(AggregationExceptions.CONTENT_URI,<br style="line-height:25px"> values,null,null);<br style="line-height:25px"> values.clear();<br style="line-height:25px"> Log.i("hubin",rawContactId+"unlink"+rawContactId2);<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
java.lang.Object
android.provider.ContactsContract.AggregationExceptions
ClassOverview
Constantsforthecontactaggregationexceptionstable,
whichcontainsaggregationrulesoverridingthoseusedbyautomaticaggregation.
Thistypeonlysupportsqueryandupdate.Neitherinsertnordeletearesupported.
该类为用户提供了控制rawContact组不组成一个contactaggregation的方式。
<wbr style="line-height:25px">对于该表只能查询和更新。不能插入和删除。插入和删除都是由系统来控制的。</wbr><wbr style="line-height:25px"><br style="line-height:25px"> Columns<br style="line-height:25px"> AggregationExceptions<br style="line-height:25px"> intTYPEread/writeThetypeofexception:TYPE_KEEP_TOGETHER,TYPE_KEEP_SEPARATEorTYPE_AUTOMATIC.<br style="line-height:25px"> longRAW_CONTACT_ID1read/writeAreferencetothe_IDoftherawcontactthattheruleappliesto.<br style="line-height:25px"> longRAW_CONTACT_ID2read/writeAreferencetotheother_IDoftherawcontactthattheruleappliesto.<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">数据查询:</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">c=managedQuery(AggregationExceptions.CONTENT_URI,<br style="line-height:25px"> newString[]{AggregationExceptions.TYPE,AggregationExceptions.RAW_CONTACT_ID1,<br style="line-height:25px"> AggregationExceptions.RAW_CONTACT_ID2},<br style="line-height:25px"> null,null,null);</span><br style="line-height:25px"> 注意这里查询到的只是TYPE为TYPE_KEEP_TOGETHER和TYPE_KEEP_SEPARATE的项。<br style="line-height:25px"> 系统的意思就是在这里只是定义Exception的Aggregation规则。默认的为TYPE_AUTOMATIC,自然不在此表。想想如果TYPE_AUTOMATIC得要定义在表中的话,那这个表的数据量就太大了。而且对于TYPE_AUTOMATIC的关系没有必要再定义,不定义就是TYPE_AUTOMATIC。<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">数据更新:</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> 需要注意的是对于想让一个集合的各元素的TYPE做改变时,最好对各个元素和其他的关系(TYPE)都做改变。<br style="line-height:25px"> 比如想让A,B,C变成一组。不应该简单的让A与B,A与C变成TYPE_KEEP_TOGETHER。<br style="line-height:25px"> 而应该让A与B,A与C,B与C都变成TYPE_KEEP_TOGETHER。<br style="line-height:25px"><span style="line-height:25px">例1</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">void</span><span style="color:#ff6600; line-height:25px">doAggregationAllByBatch()</span>{<br style="line-height:25px"><span style="color:#0000ff; line-height:25px">Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);</span><span style="color:#808080; line-height:25px">//注意这里的条件</span><br style="line-height:25px"><br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ArrayList<ContentProviderOperation>ops=newArrayList<ContentProviderOperation>();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"> ops.add(ContentProviderOperation.newUpdate(<br style="line-height:25px"> AggregationExceptions.CONTENT_URI).withValue(<br style="line-height:25px"> AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_TOGETHER).withValue(<br style="line-height:25px"> AggregationExceptions.RAW_CONTACT_ID1,rawContactId)<br style="line-height:25px"> .withValue(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2).build());<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> try{<br style="line-height:25px"> getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);<br style="line-height:25px"> }catch(Exceptione){<br style="line-height:25px"> e.printStackTrace();<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><span style="line-height:25px">例2</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">void</span><span style="color:#ff6600; line-height:25px">doAggregationAll</span>(){<br style="line-height:25px"> Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);<br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ContentValuesvalues=newContentValues();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"><br style="line-height:25px"> values.put(AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_TOGETHER);<br style="line-height:25px"> values.put(AggregationExceptions.RAW_CONTACT_ID1,rawContactId);<br style="line-height:25px"> values<br style="line-height:25px"> .put(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2);<br style="line-height:25px"> getContentResolver().update(AggregationExceptions.CONTENT_URI,<br style="line-height:25px"> values,null,null);<br style="line-height:25px"> values.clear();<br style="line-height:25px"> Log.i("hubin",rawContactId+"unlink"+rawContactId2);<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><span style="line-height:25px">例3</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">void</span><span style="color:#ff6600; line-height:25px">doUnAggregationAllByBatch</span>(){<br style="line-height:25px"> Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);<br style="line-height:25px"><br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ArrayList<ContentProviderOperation>ops=newArrayList<ContentProviderOperation>();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"> ops.add(ContentProviderOperation.newUpdate(<br style="line-height:25px"> AggregationExceptions.CONTENT_URI).withValue(<br style="line-height:25px"> AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_SEPARATE).withValue(<br style="line-height:25px"> AggregationExceptions.RAW_CONTACT_ID1,rawContactId)<br style="line-height:25px"> .withValue(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2).build());<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> try{<br style="line-height:25px"> getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);<br style="line-height:25px"> }catch(Exceptione){<br style="line-height:25px"> e.printStackTrace();<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><span style="line-height:25px">例4</span>:<br style="line-height:25px"> voiddoUnAggregationAll(){<br style="line-height:25px"> Cursorc=getContentResolver().query(RawContacts.CONTENT_URI,null,<br style="line-height:25px"> RawContacts.DELETED+"=0",null,null);<br style="line-height:25px"> intcount=c.getCount();<br style="line-height:25px"> intrawContactIdCol=c.getColumnIndex(RawContacts._ID);<br style="line-height:25px"> longrawContactIds[]=newlong[count];<br style="line-height:25px"> inti=0;<br style="line-height:25px"> while(c.moveToNext()){<br style="line-height:25px"> rawContactIds[i++]=c.getLong(rawContactIdCol);<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> longrawContactId=0;<br style="line-height:25px"> longrawContactId2=0;<br style="line-height:25px"> ContentValuesvalues=newContentValues();<br style="line-height:25px"> for(i=0;i<count;i++){<br style="line-height:25px"> rawContactId=rawContactIds<wbr style="line-height:25px">;<br style="line-height:25px"> for(intj=i+1;j<count;j++){<br style="line-height:25px"> rawContactId2=rawContactIds[j];<br style="line-height:25px"><br style="line-height:25px"> values.put(AggregationExceptions.TYPE,<br style="line-height:25px"> AggregationExceptions.TYPE_KEEP_SEPARATE);<br style="line-height:25px"> values.put(AggregationExceptions.RAW_CONTACT_ID1,rawContactId);<br style="line-height:25px"> values<br style="line-height:25px"> .put(AggregationExceptions.RAW_CONTACT_ID2,<br style="line-height:25px"> rawContactId2);<br style="line-height:25px"> getContentResolver().update(AggregationExceptions.CONTENT_URI,<br style="line-height:25px"> values,null,null);<br style="line-height:25px"> values.clear();<br style="line-height:25px"> Log.i("hubin",rawContactId+"unlink"+rawContactId2);<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr>