public int WriteContact(Contact contact)
        {
            List <ContentProviderOperation> ops = new List <ContentProviderOperation>();
            int rawContactInsertIndex           = ops.Count;

            ops.Add(ContentProviderOperation
                    .NewInsert(Android.Provider.ContactsContract.RawContacts.ContentUri)
                    .WithValue(Android.Provider.ContactsContract.RawContacts.InterfaceConsts.AccountType, null)
                    .WithValue(Android.Provider.ContactsContract.RawContacts.InterfaceConsts.AccountName, null).Build());
            ops.Add(ContentProviderOperation
                    .NewInsert(Android.Provider.ContactsContract.Data.ContentUri)
                    .WithValueBackReference(Android.Provider.ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex)
                    .WithValue(Android.Provider.ContactsContract.Data.InterfaceConsts.Mimetype, Android.Provider.ContactsContract.CommonDataKinds.StructuredName.ContentItemType)
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.StructuredName.DisplayName, contact.FirstName) // Name of the person
                    .Build());
            ops.Add(ContentProviderOperation
                    .NewInsert(Android.Provider.ContactsContract.Data.ContentUri)
                    .WithValueBackReference(
                        ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex)
                    .WithValue(Android.Provider.ContactsContract.Data.InterfaceConsts.Mimetype, Android.Provider.ContactsContract.CommonDataKinds.Phone.ContentItemType)
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.Phone.Number, contact.Number)                   // Number of the person
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, "mobile").Build()); // Type of mobile number
            try
            {
                Android.App.Application.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
            }
            catch (Exception ex)
            {
                //
            }
            return(0);
        }
示例#2
0
        private static void CleanupPlaylist(Context context, long playlistId, ICursor cursor)
        {
            var idCol = cursor.GetColumnIndexOrThrow(Playlists.Members.AudioId);
            var uri   = Uri.Parse($"content://media/external/audio/playlists/{playlistId}/members");

            var ops = new List <ContentProviderOperation> {
                ContentProviderOperation.NewDelete(uri).Build()
            };

            var f = 100;

            if (cursor.MoveToFirst() && cursor.Count > 0)
            {
                do
                {
                    var builder = ContentProviderOperation.NewInsert(uri)
                                  .WithValue(Playlists.Members.PlayOrder, cursor.Position)
                                  .WithValue(Playlists.Members.AudioId, cursor.GetLong(idCol));

                    if ((cursor.Position + 1) % f == 0)
                    {
                        builder.WithYieldAllowed(true);
                    }

                    ops.Add(builder.Build());
                } while (cursor.MoveToNext());
            }

            context.ContentResolver.ApplyBatch(MediaStore.Authority, ops);
        }
        /**
         * Accesses the Contacts content provider directly to insert a new contact.
         * <p>
         * The contact is called "__DUMMY ENTRY" and only contains a name.
         */
        void InsertDummyContact()
        {
            // Two operations are needed to insert a new contact.
            var operations = new List <ContentProviderOperation> (2);

            // First, set up a new raw contact.
            ContentProviderOperation.Builder op =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri)
                .WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null)
                .WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            operations.Add(op.Build());

            // Next, set the name for the contact.
            op = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                 .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                 .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                            ContactsContract.CommonDataKinds.StructuredName.ContentItemType)
                 .WithValue(ContactsContract.CommonDataKinds.StructuredName.DisplayName, DUMMY_CONTACT_NAME);
            operations.Add(op.Build());

            // Apply the operations.
            try {
                Activity.ContentResolver.ApplyBatch(ContactsContract.Authority, operations);
            } catch (RemoteException e) {
                CommonSampleLibrary.Log.Debug(TAG, "Could not add a new contact: " + e.Message);
            } catch (OperationApplicationException e) {
                CommonSampleLibrary.Log.Debug(TAG, "Could not add a new contact: " + e.Message);
            }
        }
示例#4
0
        public static void ParseRoom(RoomXml input, List <ContentProviderOperation> batch, ContentResolver resolver)
        {
            ContentProviderOperation.Builder builder = ContentProviderOperation.NewInsert(ScheduleContract.Rooms.CONTENT_URI);

            builder.WithValue(ScheduleContract.Rooms.ROOM_ID, input.Id);
            builder.WithValue(ScheduleContract.Rooms.ROOM_NAME, input.Name);
            builder.WithValue(ScheduleContract.Rooms.ROOM_FLOOR, input.Floor);

            batch.Add(builder.Build());
        }
        public static void ParseSessions(SessionXml input, List <ContentProviderOperation> batch, ContentResolver resolver)
        {
            ContentProviderOperation.Builder builder = ContentProviderOperation.NewInsert(ScheduleContract.Sessions.CONTENT_URI);
            builder.WithValue(ScheduleContract.SyncColumns.UPDATED, 0);

            if (input.SessionId == null)
            {
                input.SessionId = ScheduleContract.Sessions.GenerateSessionId(input.Title);
            }

            if (input.RoomId != null)
            {
                builder.WithValue(ScheduleContract.Sessions.ROOM_ID, input.RoomId);
            }

            if (input.Abstract != null)
            {
                builder.WithValue(ScheduleContract.Sessions.SESSION_ABSTRACT, input.Abstract);
            }
            else
            {
                builder.WithValue(ScheduleContract.Sessions.SESSION_ABSTRACT, "");
            }

            builder.WithValue(ScheduleContract.Sessions.SESSION_ID, input.SessionId);
            builder.WithValue(ScheduleContract.Sessions.SESSION_TITLE, input.Title);

            // Use empty strings to make sure SQLite search trigger has valid data
            // for updating search index.
            builder.WithValue(ScheduleContract.Sessions.SESSION_REQUIREMENTS, "");
            builder.WithValue(ScheduleContract.Sessions.SESSION_KEYWORDS, "");

            input.BlockId = ParserUtils.FindBlock(input.Title, input.Start, input.End);
            builder.WithValue(ScheduleContract.Sessions.BLOCK_ID, input.BlockId);

            // Propagate any existing starred value
            Uri sessionUri = ScheduleContract.Sessions.BuildSessionUri(input.SessionId);
            int starred    = QuerySessionStarred(sessionUri, resolver);

            if (starred != -1)
            {
                builder.WithValue(ScheduleContract.Sessions.SESSION_STARRED, starred);
            }

            batch.Add(builder.Build());

            if (input.TrackId != null)
            {
                // TODO: support parsing multiple tracks per session
                Uri sessionTracks = ScheduleContract.Sessions.BuildTracksDirUri(input.SessionId);
                batch.Add(ContentProviderOperation.NewInsert(sessionTracks)
                          .WithValue(ScheduleDatabase.SessionsTracks.SESSION_ID, input.SessionId)
                          .WithValue(ScheduleDatabase.SessionsTracks.TRACK_ID, input.TrackId).Build());
            }
        }
示例#6
0
        //https://ghj1001020.tistory.com/4
        public void insertContacts(string contactstext)
        {
            JObject jo      = JObject.Parse(contactstext);
            string  cname   = jo["name"].ToString();
            string  cnumber = jo["number"].ToString();

            jsonview      = FindViewById <TextView>(Resource.Id.jsontest);
            jsonview.Text = cname + cnumber;

            List <ContentProviderOperation> operations = new List <ContentProviderOperation>();

            ContentProviderOperation.Builder builder =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AggregationMode,
                              AggregationMode.Disabled.GetHashCode());
            operations.Add(builder.Build());

            //name
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.DisplayName, cname);
            operations.Add(builder.Build());

            //Number
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, cnumber);

            /*
             * builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type,
             *                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom);
             * builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "QRnumber");
             */
            operations.Add(builder.Build());

            ContentProviderResult[] res;
            try
            {
                res = this.ContentResolver.ApplyBatch(ContactsContract.Authority, operations);
                Toast.MakeText(this, "Success", ToastLength.Long).Show();
            }
            catch
            {
                Toast.MakeText(this, "Fail", ToastLength.Long).Show();
            }

            //출처: https://ghj1001020.tistory.com/4 [혁준 블로그] Android studio
            //https://forums.xamarin.com/discussion/158608/how-to-get-the-value-of-contactscontract-rawcontacts-aggregation-mode-disabled-in-xamarin  xamarin
        }
        public static ContentProviderOperation ParseTracks(TrackXml input)
        {
            ContentProviderOperation.Builder builder = ContentProviderOperation.NewInsert(ScheduleContract.Tracks.CONTENT_URI);

            input.TrackId = ParserUtils.SanitizeId(input.Name);

            builder.WithValue(ScheduleContract.Tracks.TRACK_ID, input.TrackId);
            builder.WithValue(ScheduleContract.Tracks.TRACK_NAME, input.Name);
            builder.WithValue(ScheduleContract.Tracks.TRACK_COLOR, input.Color);
            builder.WithValue(ScheduleContract.Tracks.TRACK_ABSTRACT, input.Abstract);

            return(builder.Build());
        }
示例#8
0
        public static ContentProviderOperation ParseBlock(BlocksXml input)
        {
            ContentProviderOperation.Builder builder = ContentProviderOperation.NewInsert(ScheduleContract.Blocks.CONTENT_URI);

            var blockId = ScheduleContract.Blocks.GenerateBlockId(input.StartTime, input.EndTime);

            builder.WithValue(ScheduleContract.Blocks.BLOCK_ID, blockId);
            builder.WithValue(ScheduleContract.Blocks.BLOCK_TITLE, input.Title);
            builder.WithValue(ScheduleContract.Blocks.BLOCK_START, input.StartTime);
            builder.WithValue(ScheduleContract.Blocks.BLOCK_END, input.EndTime);
            builder.WithValue(ScheduleContract.Blocks.BLOCK_TYPE, input.BlockType);

            return(builder.Build());
        }
        private void Addnewcontact_Click(object sender, EventArgs e)
        {
            EditText txtfirstname = (EditText)FindViewById(Resource.Id.edtfirstname);
            EditText txtlastname  = (EditText)FindViewById(Resource.Id.edtlastname);
            EditText txtphoneno   = (EditText)FindViewById(Resource.Id.edtphoneno);
            string   lastname     = (txtlastname.Text).ToString();
            string   firstname    = (txtfirstname.Text).ToString();
            string   phone        = (txtphoneno.Text).ToString();

            List <ContentProviderOperation> contactadd = new List <ContentProviderOperation>();

            ContentProviderOperation.Builder builder =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            contactadd.Add(builder.Build());

            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, lastname);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, firstname);
            contactadd.Add(builder.Build());

            //Number
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, phone);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Mobile");
            contactadd.Add(builder.Build());

            //Add the new contact
            ContentProviderResult[] res;
            try
            {
                res = ContentResolver.ApplyBatch(ContactsContract.Authority, contactadd);
                Toast.MakeText(this, "Contact added sucessfully", ToastLength.Short).Show();
            }
            catch
            {
                Toast.MakeText(this, "Contact not added", ToastLength.Long).Show();
            }
        }
示例#10
0
        public void SaveContact()
        {
            // overview on contacts provider - http://developer.android.com/guide/topics/providers/contacts-provider.html

            var name  = FindViewById <EditText>(Resource.Id.etName).Text;
            var phone = FindViewById <EditText>(Resource.Id.etPhone).Text;

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

            ContentProviderOperation.Builder builder =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            //For update use -  ContentProviderOperation.NewUpdate(ContactsContract.RawContacts.ContentUri);

            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, "twitter.com");
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, "*****@*****.**");
            ops.Add(builder.Build());

            //Name
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, name);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.DisplayName, name);
            ops.Add(builder.Build());

            //Number
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, phone);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Work");
            ops.Add(builder.Build());

            //Add the new contact
            try
            {
                ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
                Toast.MakeText(this, "Contact saved", ToastLength.Short).Show();
            }
            catch
            {
                Toast.MakeText(this, "Contact somehow failed to save", ToastLength.Short).Show();
            }
        }
        /// <summary>
        /// Builds ContentProviderOperations for adding/removing reminders.
        /// Specifically intended for use by AddOrUpdateEvent, as if existingEvent is omitted,
        /// this requires that the operations are added to a batch in which the first operation
        /// inserts the event.
        /// </summary>
        /// <param name="reminders">New reminders (replacing existing reminders, if any)</param>
        /// <param name="existingEvent">(optional) Existing event to update reminders for</param>
        /// <returns>List of ContentProviderOperations for applying reminder updates as part of a batched update</returns>
        private static IList <ContentProviderOperation> BuildReminderUpdateOperations(IList <CalendarEventReminder> reminders, CalendarEvent existingEvent = null)
        {
            var operations = new List <ContentProviderOperation>();

            // If reminders haven't changed, do nothing
            //
            if (reminders == existingEvent?.Reminders ||
                (reminders != null && existingEvent?.Reminders != null && reminders.SequenceEqual(existingEvent.Reminders)))
            {
                return(operations);
            }

            // Build operations that remove all existing reminders and add new ones

            if (existingEvent?.Reminders != null)
            {
                operations.AddRange(existingEvent.Reminders.Select(reminder =>
                                                                   ContentProviderOperation.NewDelete(_remindersUri)
                                                                   .WithSelection($"{CalendarContract.Reminders.InterfaceConsts.EventId} = {existingEvent.ExternalID}", null)
                                                                   .Build()));
            }

            if (reminders != null)
            {
                if (existingEvent != null)
                {
                    operations.AddRange(reminders.Select(reminder =>
                                                         ContentProviderOperation.NewInsert(_remindersUri)
                                                         .WithValues(reminder.ToContentValues(existingEvent.ExternalID))
                                                         .Build()));
                }
                else
                {
                    // This assumes that these operations are being added to a batch in which the first operation
                    // is the event insertion operation
                    //
                    operations.AddRange(reminders.Select(reminder =>
                                                         ContentProviderOperation.NewInsert(_remindersUri)
                                                         .WithValues(reminder.ToContentValues())
                                                         .WithValueBackReference(CalendarContract.Reminders.InterfaceConsts.EventId, 0)
                                                         .Build()));
                }
            }

            return(operations);
        }
示例#12
0
        public void AddContact(String displayName, string mobileNumber, String email)
        {
            List <ContentProviderOperation> ops = new List <ContentProviderOperation>();

            int rawContactInsertIndex = ops.Count;

            ops.Add(ContentProviderOperation.NewInsert(Android.Provider.ContactsContract.RawContacts.ContentUri)
                    .WithValue(Android.Provider.ContactsContract.RawContacts.InterfaceConsts.AccountType, null)
                    .WithValue(Android.Provider.ContactsContract.RawContacts.InterfaceConsts.AccountName, null).Build());

            //Display Name

            ops.Add(ContentProviderOperation
                    .NewInsert(Android.Provider.ContactsContract.Data.ContentUri)
                    .WithValueBackReference(Android.Provider.ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex)
                    .WithValue(Android.Provider.ContactsContract.Data.InterfaceConsts.Mimetype, Android.Provider.ContactsContract.CommonDataKinds.StructuredName.ContentItemType)
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.StructuredName.DisplayName, displayName).Build()); // Name of the person

            //mobile number

            ops.Add(ContentProviderOperation
                    .NewInsert(Android.Provider.ContactsContract.Data.ContentUri)
                    .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex)
                    .WithValue(Android.Provider.ContactsContract.Data.InterfaceConsts.Mimetype, Android.Provider.ContactsContract.CommonDataKinds.Phone.ContentItemType)
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.Phone.Number, mobileNumber)                     // Number of the person
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, "mobile").Build()); // Type of mobile number

            //email Address
            ops.Add(ContentProviderOperation
                    .NewInsert(ContactsContract.Data.ContentUri)
                    .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex)
                    .WithValue(Android.Provider.ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Email.ContentItemType)
                    .WithValue(Android.Provider.ContactsContract.CommonDataKinds.Email.Address, email).Build()); // Email Address
            //.WithValue(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK)

            // Asking the Contact provider to create a new contact
            try
            {
                ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, "Exception: " + ex.Message, ToastLength.Long).Show();
            }
        }
        public override List <ContentProviderOperation> Parse(XDocument input, ContentResolver resolver)
        {
            List <ContentProviderOperation> batch = new List <ContentProviderOperation>();

            // Clear any existing suggestion words
            batch.Add(ContentProviderOperation.NewDelete(ScheduleContract.SearchSuggest.CONTENT_URI).Build());


            var suggestions = from x in input.Descendants("word")
                              select new TagXml
            {
                Word = x.Value
            };

            foreach (var item in suggestions)
            {
                batch.Add(ContentProviderOperation.NewInsert(ScheduleContract.SearchSuggest.CONTENT_URI).WithValue(SearchManager.SuggestColumnText1, item.Word).Build());
            }

            return(batch);
        }
示例#14
0
        /*
         * Java:
         * public static String InsertZap(String data, Context context) {
         * try {
         *  String surename = "zapi_" + data;
         *  String tel = "+" + data;
         *  InsertNoTry(surename, tel, context);
         * }catch(Exception ex){
         *  return ex.getMessage();
         * }
         * return "";
         * }
         * private static void InsertNoTry(String nameSurname, String telephone, Context context) throws Exception {
         * ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
         * int rawContactInsertIndex = ops.size();
         *
         * 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(ContactsContract.Data.CONTENT_URI)
         *      .withValueBackReference(
         *              ContactsContract.Data.RAW_CONTACT_ID,
         *              rawContactInsertIndex)
         *      .withValue(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
         *      .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, telephone).build());
         * ops.add(ContentProviderOperation
         *      .newInsert(ContactsContract.Data.CONTENT_URI)
         *      .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
         *              rawContactInsertIndex)
         *      .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
         *      .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, nameSurname)
         *      .build());
         *
         * ContentProviderResult[] res = context.getContentResolver()
         *      .applyBatch(ContactsContract.AUTHORITY, ops);
         * }
         *
         */

        public static string InsertZap(String data)
        {
            //https://forums.xamarin.com/discussion/158608/how-to-get-the-value-of-contactscontract-rawcontacts-aggregation-mode-disabled-in-xamarin

            try
            {
                string lastName = "zapi_" + data;
                //string firstName = lastName;
                string phone = "+" + data;

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

                // (AccountName = null)
                ContentProviderOperation.Builder builder =
                    ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
                builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
                builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
                builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AggregationMode,
                                  AggregationMode.Disabled.GetHashCode());
                ops.Add(builder.Build());

                //Name (FamilyName)
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, lastName);
                //builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, firstName);
                ops.Add(builder.Build());

                //Number
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.Phone.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, phone);
                builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type,
                                  ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom);
                builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Work");
                ops.Add(builder.Build());

                //Email
                //builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                //builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                //builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                //                  ContactsContract.CommonDataKinds.Email.ContentItemType);
                //builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, email);
                //builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type,
                //                  ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom);
                //builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Label, "Work");
                //ops.Add(builder.Build());

                //Company
                //builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                //builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                //builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                //                  ContactsContract.CommonDataKinds.Organization.ContentItemType);
                //builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Data, company);
                //builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Type,
                //                  ContactsContract.CommonDataKinds.Organization.InterfaceConsts.TypeCustom);
                //builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Label, "Work");
                //ops.Add(builder.Build());

                //Add the new contact
                ContentProviderResult[] res;
                //res = this.               ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
                res = Application.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);

                return(null); // null => ok
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        /// <summary>
        /// Add new event to a calendar or update an existing event.
        /// If a new event was added, the ExternalID property will be set on the CalendarEvent object,
        /// to support future queries/updates.
        /// </summary>
        /// <param name="calendar">Destination calendar</param>
        /// <param name="calendarEvent">Event to add or update</param>
        /// <exception cref="ArgumentException">Calendar is not specified, does not exist on device, or is read-only</exception>
        /// <exception cref="UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="InvalidOperationException">Editing recurring events is not supported</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public static async Task AddOrUpdateEventAsync(Calendar calendar, CalendarEvent calendarEvent)
        {
            if (string.IsNullOrEmpty(calendar.ExternalID))
            {
                throw new ArgumentException("Missing calendar identifier", nameof(calendar));
            }
            else
            {
                // Verify calendar exists (Android actually allows using a nonexistent calendar ID...)
                //
                var deviceCalendar = await GetCalendarByIdAsync(calendar.ExternalID).ConfigureAwait(false);

                if (deviceCalendar == null)
                {
                    throw new ArgumentException("Specified calendar not found on device");
                }
            }

            // Validate times
            if (calendarEvent.End < calendarEvent.Start)
            {
                throw new ArgumentException("End time may not precede start time", nameof(calendarEvent));
            }

            bool          updateExisting = false;
            long          existingId     = -1;
            CalendarEvent existingEvent  = null;

            await Task.Run(() =>
            {
                if (long.TryParse(calendarEvent.ExternalID, out existingId))
                {
                    if (IsEventRecurring(calendarEvent.ExternalID))
                    {
                        throw new InvalidOperationException("Editing recurring events is not supported");
                    }

                    var calendarId = GetCalendarIdForEventId(calendarEvent.ExternalID);

                    if (calendarId.HasValue && calendarId.Value.ToString() == calendar.ExternalID)
                    {
                        updateExisting = true;
                        existingEvent  = GetEventById(calendarEvent.ExternalID);
                    }
                }

                bool allDay = calendarEvent.AllDay;
                var start   = allDay
                    ? DateTime.SpecifyKind(calendarEvent.Start.Date, DateTimeKind.Utc)
                    : calendarEvent.Start;
                var end = allDay
                    ? DateTime.SpecifyKind(calendarEvent.End.Date, DateTimeKind.Utc)
                    : calendarEvent.End;

                var eventValues = new ContentValues();
                eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId,
                                calendar.ExternalID);
                eventValues.Put(CalendarContract.Events.InterfaceConsts.Title,
                                calendarEvent.Title);
                eventValues.Put(CalendarContract.Events.InterfaceConsts.Description,
                                calendarEvent.Description);
                eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart,
                                DateConversions.GetDateAsAndroidMS(start));
                eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend,
                                DateConversions.GetDateAsAndroidMS(end));
                eventValues.Put(CalendarContract.Events.InterfaceConsts.AllDay,
                                allDay ? 1 : 0);
                eventValues.Put(CalendarContract.Events.InterfaceConsts.EventLocation,
                                calendarEvent.Location ?? string.Empty);

                try
                {
                    if (!string.IsNullOrEmpty(calendarEvent.EventColorString) && calendarEvent.EventColor.A > 0)
                    {
                        eventValues.Put(CalendarContract.Events.InterfaceConsts.EventColor,
                                        calendarEvent.EventColor.ToAndroid());
                    }
                }
                catch { }

                // If we're updating an existing event, don't mess with the existing
                // time zone (since we don't support explicitly setting it yet).
                // *Unless* we're toggling the "all day" setting
                // (because that would mean the time zone is UTC rather than local...).
                //
                if (!updateExisting || allDay != existingEvent?.AllDay)
                {
                    eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone,
                                    allDay
                        ? Java.Util.TimeZone.GetTimeZone("UTC")?.ID ?? string.Empty
                        : Java.Util.TimeZone.Default.ID);
                }

                var operations = new List <ContentProviderOperation>();

                var eventOperation = updateExisting
                    ? ContentProviderOperation.NewUpdate(ContentUris.WithAppendedId(_eventsUri, existingId))
                    : ContentProviderOperation.NewInsert(_eventsUri);

                eventOperation = eventOperation.WithValues(eventValues);
                operations.Add(eventOperation.Build());

                operations.AddRange(BuildReminderUpdateOperations(calendarEvent.Reminders, existingEvent));

                try
                {
                    var results = ApplyBatch(operations);

                    if (!updateExisting)
                    {
                        calendarEvent.ExternalID = results[0].Uri.LastPathSegment;
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }).ConfigureAwait(false);
        }
示例#16
0
        public bool AddContacts(QContact qc)
        {
            Console.WriteLine("export contacts android");

            List <ContentProviderOperation> ops = new List <ContentProviderOperation>();
            int rawContactInsertIndex           = ops.Count;

            ContentProviderOperation.Builder builder =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            ops.Add(builder.Build());

            //Name
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, qc.LastName);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, qc.FirstName);
            ops.Add(builder.Build());

            //MOBILE
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, qc.Mobile);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Primary Phone");
            ops.Add(builder.Build());

            //Email
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Email.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, qc.Email);
            builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Label, "Email");
            ops.Add(builder.Build());

            //Address
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredPostal.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Street, qc.Addr);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.City, "");
            ops.Add(builder.Build());

            //others-> birthday fb
            StringBuilder sb = new StringBuilder();

            sb.Append("Birthday:").Append(qc.Birthday.ToString("MM/dd/yyyy")).Append(", Facebook:").Append(qc.Facebook)
            .Append(", Instagram:").Append(qc.Instagram).Append(", Twitter:").Append(qc.Twitter)
            .Append(", Linkedin:").Append(qc.LinkedIn).Append(", Skype:").Append(qc.Skype);
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Note.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Note.InterfaceConsts.Data1, sb.ToString());
            ops.Add(builder.Build());

            //company
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Organization.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Data, qc.Company);
            ops.Add(builder.Build());

            //url
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Website.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Data, qc.URL);
            ops.Add(builder.Build());

            //homePhone
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, qc.HomePhone);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Home");
            ops.Add(builder.Build());

            //workPhone
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, qc.WorkPhone);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Work");
            ops.Add(builder.Build());

            //homeFax
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, qc.HomeFax);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Home Fax");
            ops.Add(builder.Build());

            //workFax
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, qc.WorkFax);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Work Fax");
            ops.Add(builder.Build());

            try
            {
                var res = Forms.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
                return(true);
                //Toast.MakeText(Forms.Context, "Contact Saved", ToastLength.Short).Show();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
                //Toast.MakeText(Forms.Context, "Contact Not Saved", ToastLength.Long).Show();
                return(false);
            }
        }
示例#17
0
        public void rehberEkle(string FirstName, string PhoneNumber)
        {
            List <ContentProviderOperation> ops = new List <ContentProviderOperation>();
            int rawContactInsertIndex           = ops.Count;

            ContentProviderOperation.Builder builder =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            ops.Add(builder.Build());

            //Name
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            //builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, LastName);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, FirstName);
            ops.Add(builder.Build());

            //Number
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, PhoneNumber);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                              ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Primary Phone");
            ops.Add(builder.Build());

            /*
             * //Email
             * builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
             * builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
             * builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
             *  ContactsContract.CommonDataKinds.Email.ContentItemType);
             * builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, Email);
             * builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type,
             *  ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom);
             * builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Label, "Email");
             * ops.Add(builder.Build());
             *
             * //Address
             * builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
             * builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
             * builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
             *  ContactsContract.CommonDataKinds.StructuredPostal.ContentItemType);
             * builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Street, Address1);
             * builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.City, Address2);
             * ops.Add(builder.Build());
             */
            try
            {
                var res = ContentResolver.ApplyBatch(ContactsContract.Authority, ops);

                Toast.MakeText(this, "Contact Saved", ToastLength.Short).Show();
            }
            catch
            {
                Toast.MakeText(this, "Contact Not Saved", ToastLength.Long).Show();
            }
        }
示例#18
0
        private void CadastraContatos(List <Contato> contatos)
        {
            foreach (Contato contatoArquivo in contatos)
            {
                List <ContentProviderOperation> ops = new List <ContentProviderOperation>();
                //contador de contatos que serve como indice para adicionar novos contatos
                int rawContactInsertIndex = ops.Count;

                //Agrupador dos dados do contato - nele serao adicionados todos os dados do contato
                ContentProviderOperation.Builder builder =
                    ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
                builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
                builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
                ops.Add(builder.Build());

                //Nome
                //instancia um novo objeto onde serao inseridos os dados do contato, buscando pela constante do sistema que possui o endereco
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                //criar uma referencia com um identificador unico no agrupador de dados
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
                //define o tipo de objeto que sera inserido no agrupador e modelo de contexto
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
                //define valores do contato, podem ser utilizados quaisquer atributos do contato e um respectivo valor nas 2 chamadas abaixo
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, contatoArquivo.SobrenomeFuncionario);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, contatoArquivo.NomeFuncionario);
                //adiciona a nova entrada ao agrupador de dados.
                ops.Add(builder.Build());

                //Empresa
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.Organization.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.Organization.Company, "STEFANINI - Agenda Corporativa");
                ops.Add(builder.Build());

                //Adicionando telefones
                int nItem = 1;
                //percore a lista de todos os telefones existentes no contato
                foreach (Telefone telefone in contatoArquivo.Telefones)
                {
                    builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                    builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
                    builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                      ContactsContract.CommonDataKinds.Phone.ContentItemType);
                    builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, telefone.DDD + telefone.Numero);
                    builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                                      ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
                    builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Telefone " + nItem);
                    ops.Add(builder.Build());
                    nItem++;
                }

                nItem = 1;
                //percorre a lista de todos os emails existentes no contato.
                foreach (string email in contatoArquivo.Emails)
                {
                    //Email
                    builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                    builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, rawContactInsertIndex);
                    builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                      ContactsContract.CommonDataKinds.Email.ContentItemType);
                    builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, email);
                    builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type,
                                      ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom);
                    builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Label, "Email " + nItem);
                    ops.Add(builder.Build());
                    nItem++;
                }


                try
                {
                    //Utiliza o gerenciador de conteudo verificando se o usuario possui permissao de escrita e adiciona o mesmo na lista de contatos
                    var res = Forms.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
                }
                catch
                {
                }
            }
        }
示例#19
0
        private void createContact()
        {
            System.Collections.Generic.List <ContentProviderOperation> ops = new System.Collections.Generic.List <ContentProviderOperation>();

            ContentProviderOperation.Builder builder = ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            ops.Add(builder.Build());

            //Name
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, "fast food");
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, "Ocio");
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.DisplayName, "Ocio");
            ops.Add(builder.Build());

            //Number
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Phone.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, "0125280747");
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Prenotazioni");
            ops.Add(builder.Build());

            //Photo
            Android.Graphics.Bitmap bitmap = Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon);
            System.IO.MemoryStream  stream = new System.IO.MemoryStream();
            bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, stream);
            byte[] data = stream.ToArray();
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Photo.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Photo.InterfaceConsts.Data15, data);
            ops.Add(builder.Build());

            //Website
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Website.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Website.Url, "https://www.facebook.com/ocioivrea/");
            builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Website.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Label, "Sito web");
            ops.Add(builder.Build());

            //Address
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.StructuredPostal.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.City, "Ivrea");
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Country, "Italia");
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Postcode, "10015");
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Street, "Corso Nigra 67");
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Region, "TO");
            builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Type, ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Label, "Indirizzo");
            ops.Add(builder.Build());

            //Email
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Email.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, "*****@*****.**");
            builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom);
            builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Label, "Email");
            ops.Add(builder.Build());

            //Company

            /*
             * builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
             * builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
             * builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Organization.ContentItemType);
             * builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Data, lkw + " (" + fromCountry + ">" + toCountry + ")");
             * builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Organization.InterfaceConsts.TypeCustom);
             * builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Label, "Work");
             * ops.Add(builder.Build());
             */

            ContentProviderResult[] res = this.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
            Toast.MakeText(this, "Ocio aggiunto ai contatti, grazie!", ToastLength.Long).Show();
        }
示例#20
0
        private Contact SaveNew(Contact contact)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }
            if (contact.Id != null)
            {
                throw new ArgumentException("Contact is not new", "contact");
            }

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

            ContentProviderOperation.Builder builder =
                ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null);
            builder.WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
            ops.Add(builder.Build());

            //Name
            builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                              ContactsContract.CommonDataKinds.StructuredName.ContentItemType);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.FamilyName, contact.LastName);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.GivenName, contact.FirstName);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.MiddleName, contact.MiddleName);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.DisplayName, contact.Nickname);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.Prefix, contact.Prefix);
            builder.WithValue(ContactsContract.CommonDataKinds.StructuredName.Suffix, contact.Suffix);
            ops.Add(builder.Build());

            //Addresses
            foreach (var item in contact.Addresses)
            {
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.StructuredPostal.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Street, item.StreetAddress);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type, ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Postcode, item.PostalCode);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.City, item.City);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Country, item.Country);
                builder.WithValue(ContactsContract.CommonDataKinds.StructuredPostal.Region, item.Region);
                ops.Add(builder.Build());
            }

            //Number
            foreach (var item in contact.Phones)
            {
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.Phone.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, item.Number);
                builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type,
                                  ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom);
                builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, item.Label);
                ops.Add(builder.Build());
            }

            //Email
            foreach (var item in contact.Emails)
            {
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.Email.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, item.Address);
                builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type,
                                  ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom);
                builder.WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Label, item.Label);
                ops.Add(builder.Build());
            }

            //Website
            foreach (var item in contact.Websites)
            {
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Website.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.Website.Url, item.Address);
                builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Website.InterfaceConsts.TypeCustom);
                builder.WithValue(ContactsContract.CommonDataKinds.Website.InterfaceConsts.Label, "Homepage");
                ops.Add(builder.Build());
            }

            ////Notes
            //foreach (var item in contact.Notes)
            //{
            //    builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
            //    builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
            //    builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Note.ContentItemType);
            //    ...
            //    ...
            //    ops.Add(builder.Build());
            //}

            //Company
            foreach (var item in contact.Organizations)
            {
                builder = ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri);
                builder.WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0);
                builder.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype,
                                  ContactsContract.CommonDataKinds.Organization.ContentItemType);
                builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Data, item.Name);
                builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Type,
                                  ContactsContract.CommonDataKinds.Organization.InterfaceConsts.TypeCustom);
                builder.WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Label, item.Name);
                ops.Add(builder.Build());
            }

            //Add the new contact
            ContentProviderResult[] res;
            try
            {
                res = this.content.ApplyBatch(ContactsContract.Authority, ops);
                //Toast.MakeText(context, context.Resources.GetString(Resource.String.contact_saved_message), ToastLength.Short).Show();
            }
            catch
            {
                //Toast.MakeText(context, context.Resources.GetString(Resource.String.contact_not_saved_message), ToastLength.Long).Show();
            }
            return(contact);
        }
示例#21
0
        public static string InsertZap_(String data)
        {
            try
            {
                String surename = "zapi_" + data;
                String tel      = "+" + data;

                List <ContentProviderOperation> ops = new List <ContentProviderOperation>();
                {
                    //// Name
                    //ops.add(
                    //    ContentProviderOperation
                    //        .newInsert(ContactsContract.RawContacts.CONTENT_URI)
                    //        .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
                    //        .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
                    //        .build());

                    // Name
                    var builder = ContentProviderOperation
                                  .NewInsert(ContactsContract.RawContacts.ContentUri)
                                  .WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null)
                                  .WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountName, null);
                    ops.Add(builder.Build());
                }

                {
                    //// NUMBER
                    //ops.add(
                    //    ContentProviderOperation
                    //        .newInsert(ContactsContract.Data.CONTENT_URI)
                    //        .withValueBackReference(
                    //                ContactsContract.Data.RAW_CONTACT_ID,
                    //                rawContactInsertIndex)
                    //        .withValue(
                    //                ContactsContract.Contacts.Data.MIMETYPE,
                    //                ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                    //        .withValue(
                    //                ContactsContract.CommonDataKinds.Phone.NUMBER, telephone)
                    //        .build());


                    // Number
                    var builder = ContentProviderOperation
                                  .NewInsert(ContactsContract.Data.ContentUri)
                                  .WithValueBackReference(
                        ContactsContract.RawContacts.InterfaceConsts.ContactId, 0)
                                  .WithValue(
                        ContactsContract.Data.InterfaceConsts.Mimetype,
                        ContactsContract.CommonDataKinds.StructuredName.ContentItemType)
                                  .WithValue(
                        ContactsContract.CommonDataKinds.Phone.Number,
                        tel);
                    ops.Add(builder.Build());
                }

                {
                    //// DISPLAY_NAME
                    //ops.add(
                    //    ContentProviderOperation
                    //        .newInsert(ContactsContract.Data.CONTENT_URI)
                    //        .withValueBackReference(
                    //                ContactsContract.Data.RAW_CONTACT_ID,
                    //                rawContactInsertIndex)
                    //        .withValue(
                    //                ContactsContract.Data.MIMETYPE,
                    //                ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                    //        .withValue(
                    //                ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                    //                nameSurname)
                    //        .build());

                    // display Name
                    var builder = ContentProviderOperation
                                  .NewInsert(ContactsContract.Data.ContentUri)
                                  .WithValueBackReference(
                        ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                                  .WithValue(
                        ContactsContract.Data.InterfaceConsts.Mimetype,
                        ContactsContract.CommonDataKinds.StructuredName.ContentItemType)
                                  .WithValue(
                        ContactsContract.CommonDataKinds.StructuredName.DisplayName,
                        surename);
                    ops.Add(builder.Build());
                }

                //Add the new contact
                ContentProviderResult[] res;
                res = Application.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
                return(null); // null => ok
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
示例#22
0
        public void SaveContact(ContactModel contact)
        {
            var activity = MainActivity.Instance;

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

            ops.Add(ContentProviderOperation.NewInsert(ContactsContract.RawContacts.ContentUri)
                    .WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null)
                    .WithValue(ContactsContract.RawContacts.InterfaceConsts.AccountType, null)
                    .Build());

            // Name
            if (contact.Name.Text != null)
            {
                ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                        .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                        .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.StructuredName.ContentItemType)
                        .WithValue(ContactsContract.CommonDataKinds.StructuredName.DisplayName, contact.Name.Text)
                        .Build());
            }

            // Phone Numbers
            foreach (PhoneField phone in contact.PhoneNumbers)
            {
                if (!String.IsNullOrEmpty(phone.Number))
                {
                    ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                            .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                            .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Phone.ContentItemType)
                            .WithValue(ContactsContract.CommonDataKinds.Phone.Number, phone.Number)
                            .WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom)
                            .WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Data2, GetPhoneDataKind(phone))
                            .Build());
                }
            }

            // Emails
            foreach (EmailField email in contact.Emails)
            {
                if (email.Email != null)
                {
                    ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                            .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                            .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Email.ContentItemType)
                            .WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, email.Email)
                            .WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Email.InterfaceConsts.TypeCustom)
                            .WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data2, GetEmailDataKind(email))
                            .Build());
                }
            }

            // Websites
            foreach (ContactField website in contact.Websites)
            {
                if (website.Text != null)
                {
                    ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                            .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                            .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Website.ContentItemType)
                            .WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data, website.Text)
                            .WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Website.InterfaceConsts.TypeCustom)
                            .WithValue(ContactsContract.CommonDataKinds.Email.InterfaceConsts.Data2, (int)WebsiteDataKind.Work)
                            .Build());
                }
            }

            // Organization
            foreach (ContactField company in contact.Companies)
            {
                if (company.Text != null)
                {
                    ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                            .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                            .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Organization.ContentItemType)
                            .WithValue(ContactsContract.CommonDataKinds.Organization.Company, company.Text)
                            .WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Data3)

                            .Build());
                }
            }

            // Job Title
            foreach (ContactField jobTitle in contact.JobTitles)
            {
                ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                        .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                        .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Organization.ContentItemType)
                        .WithValue(ContactsContract.CommonDataKinds.Organization.Title, jobTitle.Text)
                        .WithValue(ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Type, ContactsContract.CommonDataKinds.Organization.InterfaceConsts.Data3)

                        .Build());
            }

            // Attach thumbnail
            if (System.IO.File.Exists(contact.ProfileImage))
            {
                ops.Add(ContentProviderOperation.NewInsert(ContactsContract.Data.ContentUri)
                        .WithValueBackReference(ContactsContract.Data.InterfaceConsts.RawContactId, 0)
                        .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Photo.ContentItemType)
                        .WithValue(ContactsContract.CommonDataKinds.Photo.InterfaceConsts.Data15, System.IO.File.ReadAllBytes(contact.ProfileImage))
                        .Build());
            }

            activity.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
        }