android - Delete number from contacts -
The following code allows me to display duplicate contacts. And when I try to delete it, it removes the duplicate number as well as the original number. I just want to delete this duplicate number in the list view.
This is my code.
Increases the mainActivity activity of the public class {ListView listView; ArrayList & LT; String & gt; ListItems = New ArrayList & lt; String & gt; (); Set up & lt; String & gt; DupesRemoved = New Hashet & lt; String & gt; (); String [] newList; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); ListView = (ListView) findViewById (R.id.list); String Order = Contract Contract CommonDirects Ford .DISPLAY_NAME + "ASC"; Cursor curlog = getContentResolver (). Query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, blank, empty, blank, command); Cursor cursor = null; if (! curLog = null) {while (curLog.moveToNext ()) {string str = curLog.getString (curLog.getColumnIndexOrThrow (ContactsContract.CommonDataKinds.Phone.NUMBER)); // contactid = cursor.getstring (cursor.tsta columnindextrate (contactContact.phoneloft.iid)); ListItems.add (STR); }} DupesRemoved = Search duplicate (listItems); String list string = dossessemoad.tstring (); ListString = listString.substring (1, list string .length () - 1); NewList = listString.split (","); //Arrays.sort(newList); ArrayAdapter & LT; String & gt; Adapter = new array adapter & lt; String & gt; (Main activity: this, Android .R.Let.simple_l_l_item, new list); ListView.setAdapter (adapter); } Public Zero removal (see view) {string [] info = new string [2]; For (strings: newlive) {info = (getContactInfo (s)); UpdateContact (information [0], this, information [1]); ListView.invalidateViews (); }} Public void updateContact (string ContactId, Transactions Act, string type) {/ * ASSERT: @contactId alreay have a working phone number * / ArrayList & LT; ContentProviderOperation & gt; Ops = new arreelist & lt; Content provider operation & gt; (); String selectPhone = ContactsContract.Data.CONTACT_ID + "=? And" + ContactsContract.Data.MIMETYPE + '=' '+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'" + "and" + ContactsContract.CommonDataKinds.Phone.TYPE + "=?"; String [] phoneArgs [= new String] {ContactId, type /*String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_HOME)*/}; Ops.add (ContentProviderOperation.newDelete (ContactsContract.Data.CONTENT_URI) .with selection (selection Krenfon, Fonarge) .build ()); Try {act.getContentResolver () ApplyBatch (ContactsContract.AUTHORITY, Ops); } Grip (Remote Exception e) {e.printStackTrace (); } Hold (operation application exception e) {e.printStackTrace (); }} Set Public Stabilization & lt; String & gt; Search duplicate (list & lt; string & gt; list control duplicates) {last set & lt; String & gt; SetToReturn = NewHashet & lt; String & gt; (); Last set & lt; String & gt; Set1 = NewHashet & lt; String & gt; (); (String your list: list included duplicate) {if (! Set1.add (yourInt)) {setToReturn.add (yourInt); }} Returns SatorAuttern; } Private string [] getContactInfo (string number) {string [] contactInfo = new string [2]; ContentResolver Reference = getContentResolver (); /// number is a phone number Uri Lookupuri = Uri. Along with the expected path (contactctact.online.contentfilteriUri, Yuri.Xcode (number)); String [] Mfonenumberprojekshn = {Contaktskontrktkfonelukupk_id, Contaktskontrktkfonelukupknanbr, Contaktskontrktkfonelukupktaip}; Cursor cur = context.query (lookup uriy, mfnumberber projection, empty, empty, empty); Try {if (cur.moveToFirst ()) {contactInfo [0] = cur.getString (0); ContactInfo [1] = cur.getString (2); Return contact information; }} Finally {if (cur! = Null) cur.close (); } Contact backEfO; }} hashmap archived items in critical value pairs such as duplicate keys instead of ArrayList Not allowed in a map to use.
Comments
Post a Comment