Actually what I want to do is to insert REDUNDANT contacts and without any names (just the phone number) for example I want to insert 123456789 in contact n times. No need to mention that I'm pretty new in Android So I have couple of questions:
- Where in android exactly checks if a contact is redundant?
- That checking should take some time right? and I don't want that, so is there any way to disable the checking?
here is my code that I found here on stackoverflow
package com.example.contactsoperation;
import java.util.ArrayList;
import android.Manifest;
import android.app.Activity;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.OperationApplicationException;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.view.Menu;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// protected String[] names = {"Amanda", "Candy", "Dandy"};
protected String[] numbers = {"1234567890", "1234567890", "1234567890"};
protected int[] ids = {1, 2, 3};
private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 100;
private static final int PERMISSIONS_REQUEST_WRITE_CONTACTS = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
// requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, PERMISSIONS_REQUEST_READ_CONTACTS);
requestPermissions(new String[]{Manifest.permission.WRITE_CONTACTS}, PERMISSIONS_REQUEST_WRITE_CONTACTS);
//After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method
} else {
for (int i = 0; i < numbers.length; i++) {
// writeContact(names[i], numbers[i]);
writeContact(numbers[i]);
}
}
}
private void writeContact(String numbers) {
ArrayList contentProviderOperations = new ArrayList();
//insert raw contact using RawContacts.CONTENT_URI
contentProviderOperations.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null).withValue(RawContacts.ACCOUNT_NAME, null).build());
//insert mobile number using Data.CONTENT_URI
contentProviderOperations.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, numbers).withValue(Phone.TYPE, Phone.TYPE_MOBILE).build());
try {
getApplicationContext().getContentResolver().
applyBatch(ContactsContract.AUTHORITY, contentProviderOperations);
} catch (RemoteException e) {
e.printStackTrace();
} catch (OperationApplicationException e) {
e.printStackTrace();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
P.S.
I intentionally WANT redundancy.
Actually what I'm looking for is to disable that checking because no matter the number is duplicate or not any way it takes some time to check if it is duplicate or not and imagine I want to insert 1M contacts it gets slower and slower to check if it's redundant or not
question from:
https://stackoverflow.com/questions/65932895/how-do-i-insert-redundant-contacts 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…