ich Kontakte zu SIM-Karte hinzuzufügen, ich versuche, sie scheinen auf die SIM-Karte hinzugefügt werden, aber sie sind nur sichtbar, nachdem das Gerät (auch auf die native Menschen app) Neustart ..Kontakte zur SIM-Karte hinzufügen
Hier ist der Code, ich verwende:
final Uri uri = Uri.parse("content://icc/adn");
ContentValues mContentValue = new ContentValues();
mContentValue.put("tag", contactName);
mContentValue.put("number", contactNumber);
getContentResolver().insert(uri, mContentValue);
ist es ein Problem mit sync'ing die Kontakte db nach der Kontakte zu schaffen? Wenn ja, gibt es einen Weg, Android zu zwingen, die Datenbank der Kontakte mit der SIM-Karte zu synchronisieren?
EDIT
Ok, lassen Sie mich wieder mein Problem erklären. Hier ist ein Mann, der dasselbe Problem hatte, aber es gibt keine Antwort (when adding contacts to sim card, they are only displayed after rebooting the device), also muss ich es noch einmal fragen.
ACCOUNT_TYPE: com.android.contacts.sim und ACCOUNT_NAME: SIM sind falsch für mein Handy. Ich habe Recht von KontakteContract.Settings.CONTENT_URI: com.android.huawei.phone - Telefon und com.android.huawei.sim - sim1. Hier ist mein Code:
ArrayList<ContentProviderOperation> op = new ArrayList<>();
Uri simUri = Uri.parse("content://icc/adn");
ContentValues values = new ContentValues();
values.put("tag", "NAME");
values.put("number", "77777777777");
try {
Uri uri = context.getContentResolver().insert(simUri, values);
int efid = 0,index = 0;
Pattern pattern = Pattern.compile("^content://icc/adn/(\\d+)/(\\d+)$*");
Matcher matcher = pattern.matcher(uri.toString());
if(matcher.matches()) {
index = Integer.parseInt(matcher.group(1));
efid = Integer.parseInt(matcher.group(2));
}
ArrayAdapterSpinner.Item item = adapter.getItem(spinner.getSelectedItemPosition());
op.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, "com.android.huawei.sim")
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, "sim1")
.withValue(ContactsContract.RawContacts.SYNC1,efid)
.withValue(ContactsContract.RawContacts.SYNC2,index)
.build());
op.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "NAME")
.build());
op.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, "77777777777")
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
.build());
try {
ContentProviderResult[] cprs = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, op);
} catch (Exception e) {
Log.e("ERROR", e.getMessage());
}
} catch(Exception e) {
Log.e("ERROR2", e.toString());
}
Aber Ergebnis ist:
1. Kontakt in icc/adn erstellt
2. Kontakt in RawContacts erstellt wird, aber ACCOUNT_TYPE und ACCOUNT_NAME werden ersetzt durch com.android.huawei.phone - Telefon
Erhm ... mein Fehler. Ich habe mein Problem neu erklärt. Prüfe meine Bearbeitung –
check me new edit .... getContentResolver(). NotifyChange (simUri, null); füge das hinzu, so dass es sofort erscheint. – Sahil
Es scheint nicht zu funktionieren ... Ich habe den Kontakt zu "icc/adn" hinzugefügt und Änderungen für "icc/adn" uri mitgeteilt. Ergebnis: Der Kontakt wurde zu "icc/adn" hinzugefügt, aber nicht im Gerätespeicher angezeigt. –