2017-08-25 3 views
0

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

Antwort

0

Ma kann es helfen

try{ 
       // add a row to the RawContacts table 
     ContentValues values = new ContentValues(); 
     values.put(RawContacts.ACCOUNT_TYPE, "com.android.contacts.sim"); 
     values.put(RawContacts.ACCOUNT_NAME, "SIM"); 
     Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values); 

     // get the ID of the newly-added line 
long rawContactId = ContentUris.parseId(rawContactUri); 

     // add a "name" line to the Data table, linking it to the new RawContact 
     // with the CONTACT_ID column 
values.clear(); 
values.put(Data.RAW_CONTACT_ID, rawContactId); 
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); 
values.put(StructuredName.DISPLAY_NAME, "Name"); 
cr.insert(Data.CONTENT_URI, values); 
    getContentResolver().notifyChange(Uri_Here,null); 
     // add a "phone" line to the Data table, linking it to the new RawContact 
     // with the CONTACT_ID column 
values.clear(); 
values.put(Data.RAW_CONTACT_ID, rawContactId); 
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); 
values.put(Phone.NUMBER, "+12345678901"); 
values.put(Phone.TYPE, Phone.TYPE_MOBILE); 
cr.insert(Data.CONTENT_URI, values); 
getContentResolver().notifyChange(Uri_Here,null); 
//New Edit 
} 
catch(Exception e){ 
    //exception handling 
} 
+0

Erhm ... mein Fehler. Ich habe mein Problem neu erklärt. Prüfe meine Bearbeitung –

+0

check me new edit .... getContentResolver(). NotifyChange (simUri, null); füge das hinzu, so dass es sofort erscheint. – Sahil

+0

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. –

Verwandte Themen