Exemple #1
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());
            }
        }
        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());
        }
Exemple #4
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();
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
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 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);
            }
        }
Exemple #9
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);
            }
        }
        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);
        }
        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();
        }
Exemple #12
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
                {
                }
            }
        }
Exemple #13
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();
            }
        }