0

名前と電話番号を電話帳に追加しようとしています。常に「挿入済み」と表示されますが、電話帳には表示されません。

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

                int index = ops.size();

                ops.add(ContentProviderOperation
                        .newInsert(ContactsContract.Data.CONTENT_URI)
                        .withValueBackReference(
                                ContactsContract.Data.RAW_CONTACT_ID, index)
                        .withValue(
                                ContactsContract.Data.MIMETYPE,
                                ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                        .withValue(
                                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                                mDetail.get(position).getName())
                        .withValue(
                                ContactsContract.CommonDataKinds.Phone.NUMBER,
                                mDetail.get(position).getPhone())
                        .withValue(
                                ContactsContract.CommonDataKinds.Phone.TYPE,
                                ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
                        .build());

                try {
                    getContentResolver().applyBatch(
                            ContactsContract.AUTHORITY, ops);

                    Toast.makeText(Detail_Activity.this, "Inserted..",
                            Toast.LENGTH_SHORT).show();

                } catch (Exception e) {

                    Toast.makeText(Detail_Activity.this, e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }

提案/ヘルプをいただければ幸いです

4

1 に答える 1

0

私は解決策を持っています。できます!!

        String name = mDetail.get(position).getName();
        String phone = mDetail.get(position).getPhone();



                ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

                ops.add(ContentProviderOperation
                        .newInsert(
                                ContactsContract.RawContacts.CONTENT_URI)
                        .withValue(
                                ContactsContract.RawContacts.ACCOUNT_TYPE,
                                null)
                        .withValue(
                                ContactsContract.RawContacts.ACCOUNT_NAME,
                                null).build());

                ops.add(ContentProviderOperation
                        .newInsert(Data.CONTENT_URI)
                        .withValueBackReference(Data.RAW_CONTACT_ID, 0)
                        .withValue(Data.MIMETYPE,
                                StructuredName.CONTENT_ITEM_TYPE)
                        .withValue(StructuredName.DISPLAY_NAME, name)
                        .build());

                ops.add(ContentProviderOperation
                        .newInsert(Data.CONTENT_URI)
                        .withValueBackReference(Data.RAW_CONTACT_ID, 0)
                        .withValue(Data.MIMETYPE,
                                Phone.CONTENT_ITEM_TYPE)
                        .withValue(Phone.NUMBER, phone)
                        .withValue(Phone.TYPE, Phone.TYPE_MOBILE)
                        .build());

                try {

                    getContentResolver().applyBatch(
                            ContactsContract.AUTHORITY, ops);

                    Toast.makeText(Detail_Activity.this,
                            "Contact Saved..", Toast.LENGTH_SHORT)
                            .show();
                } catch (Exception e) {

                    Toast.makeText(Detail_Activity.this,
                            e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            } 
于 2013-09-19T17:11:20.530 に答える