The MMS source of the Qualcomm platform provides the search function, but first select the classification (name, number, information content, MMS theme), then enter the characters and search according to the classification.
In Contacts, however, no classification is required, and any matching fields are searched directly according to the input characters. In contrast, the MMS search function is cumbersome and the user experience is not good.
So let's change the code, implement MMS search, and automatically match any field.
Analysis: viewing code Telephonyprovider\src\com\android\providers\telephony\mmssmsprovider.java,
From the search statement SQL design look: The name and number of the search belongs to a category, information content and subject search belong to a category.
(Name search--First name query for number, based on number search session)
From the results of the search: name and number of search results for the thread table, information content and subject search results for SMS/MMS table
Specific design: Enter a character, either a name or a number, possibly a content, or a subject. Therefore, you need to search for each type separately, and then merge the results.
For first name and number, match or separate in where statement;
For information content and topic search, use Union to combine three SQL (as the number of query fields, you can take the same alias)
//---Add by antoon PrivateCursor getmsgsearchresult (URI Uri, Sqlitedatabase db) {String keystr= Uri.getqueryparameter ("Key_str"); String Addressstr= Uri.getqueryparameter ("Addressstr"); LOG.I ("Antoon", Log_tag + ", Keystr =" +keystr); LOG.I ("Antoon", Log_tag + ", Addressstr =" +addressstr); String threadidstring=getsearchedthreadidstring (ADDRESSSTR); LOG.I ("Antoon", Log_tag + ", threadidstring =" +threadidstring); String searchstring= "%" + addescapecharacter (keystr) + "%"; LOG.I ("Antoon", Log_tag + ", SearchString =" +searchstring); cursor cursor; if(Default_string_zero.equals (threadidstring)) {cursor=getsmsmmssearchcontent (searchstring); }Else{Cursor Cursorthread=Getsearchedthreadids (threadidstring); Cursor cursormsg=getsmsmmssearchcontent (searchstring); Cursor=NewMergecursor (Newcursor[]{cursorthread, cursormsg}); } returncursor; } Privatestring getsearchedthreadidstring (String keystr) {string[] addresses= Keystr.split (","); intCount =addresses.length; Set<Long> result =NewHashset<long>(count); for(inti = 0; I < count; i++) {String address=Addresses[i]; if(Address! =NULL&&!address.equals (PDUHEADERS.FROM_INSERT_ADDRESS_TOKEN_STR)) {Set<Long> ids =getthreadidsbyaddress (address); if(IDs! =NULL) {result.addall (IDS); } Else{log.e (Log_tag,"Address ID not found for:" +address); } } } Long[] Addressidset =Getsortedset (Result); String threadidstring=Getcommaseparatedid (Addressidset); if(Textutils.isempty (threadidstring)) {threadidstring=Default_string_zero; } returnthreadidstring; } PrivateSet<long>getthreadidsbyaddress (String address) {string SearchString= "%" + addescapecharacter (address) + "%"; BooleanIsemail =mms.isemailaddress (address); String refinedaddress= Isemail?address.tolowercase (): address; String selection= "Address like?"; String[] Selectionargs; if(isemail) {Selectionargs=Newstring[] {refinedaddress}; } Else{Selection+ = "OR" + String.Format ("phone_numbers_equal (address,?,%d)", (Musestrictphonenumbercomparation? 1:0)); Selectionargs=Newstring[] {searchstring, refinedaddress}; } cursor Cursor=NULL; Set<Long> Addressids =NewHashset<long>(); Try{sqlitedatabase db=mopenhelper.getreadabledatabase (); Cursor=Db.query ("Canonical_addresses", Id_projection, Selection, Selectionargs,NULL,NULL,NULL); if(Cursor.getcount () = = 0) { return NULL; } while(Cursor.movetonext ()) {Addressids.add (Cursor.getlong (Cursor.getcolumnindexorthrow (basecolumns._id))); } } finally { if(Cursor! =NULL) {cursor.close (); } } returnAddressids; } Private synchronizedCursor getsearchedthreadids (String threadidstring) {string Thread_query=String.Format ("Select%s from Threads WHERE (_id in (%s))", Threads_projection, threadidstring); Sqlitedatabase DB=mopenhelper.getreadabledatabase (); returndb.rawquery (Thread_query, Empty_string_array); } Private synchronizedCursor getsmsmmssearchcontent (String keystr) {string Smsquery=String.Format ("Select%s from the SMS WHERE (body like? ESCAPE ' +Search_escape_character+ "')", sms_content_projection); String Mmscontentquery=String.Format (locale.us,"Select%s from Pdu,part,addr WHERE ((part.mid=pdu._id) and" + "(addr.msg_id=pdu._id) and" + "(addr.type=%d) and" + "(part.ct= ' Text/plain ') and" + " (Body like escape ' + Search_escape_character + ')) GROUP by pdu._id ", Mms_content_projection, pduheaders.to); String Mmssubjectquery=String.Format ("Select%s from Pdu,addr WHERE (" + "(addr.msg_id = pdu._id) and (addr.type=%d) and" + "(Body like?) Escape ' + Search_escape_character + ')) GROUP by pdu._id ", Mms_subject_projection, pduheaders.to); String Rawquery=String.Format ("%s Union%s Union%s ORDER by Date ASC", Smsquery, Mmscontentquery, mmssubjectquery); Sqlitedatabase DB=mopenhelper.getreadabledatabase (); returnDb.rawquery (Rawquery,Newstring[] {keystr,keystr,keystr}); } Public Static FinalString threads_projection = "' Thread ' as Transport_type, _id, Recipient_ids, Message_count, date";
////below three query fields are the same number, field names are the samePrivate Static FinalString sms_content_projection = "' SMS ' as Transport_type, _id, address, body, date";
Private Static FinalString mms_content_projection = "' mms ' as Transport_type, pdu._id, addr.address as address, part.text as body," + "Pdu.dat E * as Date "; Private Static FinalString mms_subject_projection = "' mms ' as Transport_type, pdu._id, addr.address as address, pdu.sub as body," + "pdu.date * As Date "; //---End add
MMS Search Feature Modification