public void smsLeriCek() { smsler = new List <SMS>(); try { Android.Net.Uri uri = (neresi_ == "gelen") ? Telephony.Sms.Inbox.ContentUri : Telephony.Sms.Sent.ContentUri; SMS_TURU = (neresi_ == "gelen") ? "Gelen SMS" : "Giden SMS"; string[] neleriAlicaz = { "body", "date", "address" }; CursorLoader c_loader = new CursorLoader(activity, uri, neleriAlicaz, null, null, null); ICursor cursor = (ICursor)c_loader.LoadInBackground(); if (cursor.MoveToFirst()) { do { smsler.Add(new SMS { Gonderen = cursor.GetString(cursor.GetColumnIndex("address")), Icerik = cursor.GetString(cursor.GetColumnIndex("body")), Tarih = suankiZaman(long.Parse(cursor.GetString(cursor.GetColumnIndex("date")))).ToString(), Isim = getContactbyPhoneNumber(MainActivity.global_activity, cursor.GetString(cursor.GetColumnIndex("address"))) }); } while (cursor.MoveToNext()); } } catch (Exception) { } }
public Uri[] GetContactsUriByName(System.String selname, bool ignorecase) { selname = selname.Replace("'", "''"); string _linq1 = System.String.Concat(ContactsContract.Contacts.InterfaceConsts.DisplayName, " LIKE '", selname, "'"); string _linq2 = System.String.Concat("UPPER(", ContactsContract.Contacts.InterfaceConsts.DisplayName, ") LIKE UPPER('", selname, "')"); var loader = new CursorLoader(_context, ContactsContract.Contacts.ContentUri, null, (!ignorecase) ? (_linq1) : (_linq2), null, null); ICursor cur; cur = (ICursor)loader.LoadInBackground(); Uri[] contactsUri = new Uri[cur.Count]; if (cur.MoveToFirst()) { int c = 0; do { System.String lookupKey = cur.GetString(cur.GetColumnIndex(ContactsContract.Contacts.InterfaceConsts.LookupKey)); Uri uri = Uri.WithAppendedPath(ContactsContract.Contacts.ContentLookupUri, lookupKey); contactsUri [c] = uri; c++; } while(cur.MoveToNext()); } cur.Close(); return(contactsUri); }
protected static Contact GetContact(Context context, string selection = null, string[] selectionArgs = null) { var contact = new Contact(); var uri = ContactsContract.CommonDataKinds.Phone.ContentUri; string[] projection = { ContactsContract.CommonDataKinds.Phone.InterfaceConsts.ContactId, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts.PhotoThumbnailUri, ContactsContract.CommonDataKinds.Phone.Number, ContactsContract.CommonDataKinds.Phone.NormalizedNumber }; // Load query results var loader = new CursorLoader(context, uri, projection, selection, selectionArgs, null); var cursor = (ICursor)loader.LoadInBackground(); if (cursor.MoveToFirst()) { contact = new Contact { Id = cursor.GetLong(cursor.GetColumnIndex(projection [0])), DisplayName = cursor.GetString(cursor.GetColumnIndex(projection [1])), PhotoThumbnailId = cursor.GetString(cursor.GetColumnIndex(projection [2])), Number = cursor.GetString(cursor.GetColumnIndex(projection [3])), NormalizedNumber = cursor.GetString(cursor.GetColumnIndex(projection [4])) }; } return(contact); }
void FillContacts() { var uri = ContactsContract.Contacts.ContentUri; string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts.PhotoId }; var loader = new CursorLoader(activity, uri, projection, null, null, ContactsContract.Contacts.InterfaceConsts.DisplayName); var cursor = (ICursor)loader.LoadInBackground(); ContactList = new List <Contact>(); if (cursor.MoveToFirst()) { do { ContactList.Add(new Contact { Id = cursor.GetLong(cursor.GetColumnIndex(projection[0])), DisplayName = cursor.GetString(cursor.GetColumnIndex(projection[1])), PhotoId = cursor.GetString(cursor.GetColumnIndex(projection[2])) }); } while (cursor.MoveToNext()); } }
static int PICK_CONTACT_REQUEST = 42; // The request code protected void OnActivityResult(TaskCompletionSource <ContactInfo> tcs, ActivityResultEventArgs e) { // Check which request it is that we're responding to if (e.requestCode == PICK_CONTACT_REQUEST) { // Make sure the request was successful if (e.resultCode == Android.App.Result.Ok) { var loader = new CursorLoader(MainActivity.Instance, e.data.Data, projection, null, null, null); var cursor = (Android.Database.ICursor)loader.LoadInBackground(); var contactList = new List <ContactInfo>(); if (cursor.MoveToFirst()) { do { contactList.Add(GetContactInfoFromCursor(cursor)); } while (cursor.MoveToNext()); } tcs.SetResult(contactList.FirstOrDefault()); return; } } tcs.SetResult(null); }
void UpdateProfile() { // Write to the profile var values = new ContentValues(); values.Put(ContactsContract.Contacts.InterfaceConsts.DisplayName, "John Doe"); ContentResolver.Update(ContactsContract.Profile.ContentRawContactsUri, values, null, null); // Read the profile var uri = ContactsContract.Profile.ContentUri; // Setup the "projection" (column we want) for only the display name: string[] projection = { ContactsContract.Contacts.InterfaceConsts.DisplayName }; // Use a CursorLoader to retrieve the data: CursorLoader loader = new CursorLoader(this, uri, projection, null, null, null); ICursor cursor = (ICursor)loader.LoadInBackground(); if (cursor != null) { if (cursor.MoveToFirst()) { Console.WriteLine(cursor.GetString(cursor.GetColumnIndex(projection [0]))); } } // Navigate to the profile in the contacts app var intent = new Intent(Intent.ActionView, ContactsContract.Profile.ContentUri); StartActivity(intent); }
void GetContacts() { // Get the URI for the user's contacts: var uri = ContactsContract.Contacts.ContentUri; // Setup the "projection" (columns we want) for only the ID and display name: string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.DisplayName }; // Use a CursorLoader to retrieve the user's contacts data: CursorLoader loader = new CursorLoader(this, uri, projection, null, null, null); ICursor cursor = (ICursor)loader.LoadInBackground(); // Print the contact data (ID and DisplayName) to the console if reading back succeeds: if (cursor != null) { if (cursor.MoveToFirst()) { do { Console.WriteLine("Contact ID: {0}, Contact Name: {1}", cursor.GetString(cursor.GetColumnIndex(projection[0])), cursor.GetString(cursor.GetColumnIndex(projection[1]))); } while (cursor.MoveToNext()); } } }
public void smsLeriCek() { Android.Net.Uri uri = Telephony.Sms.Inbox.ContentUri; string[] neleriAlicaz = { "body", "date", "address" }; CursorLoader c_loader = new CursorLoader(activity, uri, neleriAlicaz, null, null, null); ICursor cursor = (ICursor)c_loader.LoadInBackground(); smsler = new List <SMS>(); if (cursor.MoveToFirst()) { do { smsler.Add(new SMS { Gonderen = "Gönderen: " + cursor.GetString(cursor.GetColumnIndex("address")), Icerik = "İçerik: " + cursor.GetString(cursor.GetColumnIndex("body")), Tarih = "Tarih: " + suankiZaman(long.Parse(cursor.GetString(cursor.GetColumnIndex("date")))) }); } while (cursor.MoveToNext()); } }
private void CreateLoader() { string[] columns = { MediaStore.Images.Media.InterfaceConsts.Data, MediaStore.Images.Media.InterfaceConsts.Id }; string orderBy = MediaStore.Images.Media.InterfaceConsts.Id; _loader = new CursorLoader(_ctx, MediaStore.Images.Media.ExternalContentUri, columns, null, null, orderBy + " DESC"); }
void FillContacts() { var uri = ContactsContract.CommonDataKinds.Phone.ContentUri; string[] projection = { ContactsContract.CommonDataKinds.Phone.Number, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts.PhotoId }; //select id,DisplayName,PhotoId where id=1 var loader = new CursorLoader(this, uri, projection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); List <Contact> contactList = new List <Contact>(); if (cursor.MoveToFirst()) { do { contactList.Add( new Contact(cursor.GetString(cursor.GetColumnIndex(projection[0])), cursor.GetString(cursor.GetColumnIndex(projection[1])), cursor.GetString(cursor.GetColumnIndex(projection[2])) ) ); } while (cursor.MoveToNext()); } string items = ""; foreach (Contact c in contactList) { items += c.DisplayName + "," + c.Number + "," + c.PhotoId; } textView1.Text = items; }
void FillContacts() { var uri = calllog.ContentUri; //var uri = ContactsContract.Contacts.ContentUri; string[] projection = { calllog.Number, calllog.Date, calllog.Duration, calllog.Type, calllog.CachedName, calllog.CachedPhotoId }; // CursorLoader introduced in Honeycomb (3.0, API11) var loader = new CursorLoader(activity, uri, projection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); contactList = new List <Contact>(); if (cursor.MoveToFirst()) { do { contactList.Add(new Contact { Number = cursor.GetString(cursor.GetColumnIndex(projection[0])), Date = cursor.GetLong(cursor.GetColumnIndex(projection[1])), Duration = cursor.GetString(cursor.GetColumnIndex(projection[2])), Type = cursor.GetString(cursor.GetColumnIndex(projection[3])), Name = cursor.GetString(cursor.GetColumnIndex(projection[4])), PhotoId = cursor.GetString(cursor.GetColumnIndex(projection[5])) }); } while (cursor.MoveToNext()); } }
/// <summary> /// Return true if the local song of id audioID is contained in the local playlist with the id of playlistID. /// </summary> /// <param name="audioID"></param> /// <param name="playlistID"></param> /// <returns></returns> public async static Task <bool> SongIsContained(long audioID, long playlistID) { Uri uri = MediaStore.Audio.Playlists.Members.GetContentUri("external", playlistID); return(await Task.Run(() => { if (Looper.MyLooper() == null) { Looper.Prepare(); } CursorLoader loader = new CursorLoader(Application.Context, uri, null, null, null, null); ICursor cursor = (ICursor)loader.LoadInBackground(); if (cursor != null && cursor.MoveToFirst()) { int idColumn = cursor.GetColumnIndex(MediaStore.Audio.Playlists.Members.AudioId); do { long id = cursor.GetLong(idColumn); if (id == audioID) { return true; } }while (cursor.MoveToNext()); cursor.Close(); } return false; })); }
public void aramaKayitlariniCek() { kayitlar = new List <Kayit>(); try { Android.Net.Uri uri = CallLog.Calls.ContentUri; string[] neleriAlicaz = { CallLog.Calls.Number, CallLog.Calls.Date, CallLog.Calls.Duration, CallLog.Calls.Type }; CursorLoader c_loader = new CursorLoader(activity, uri, neleriAlicaz, null, null, null); ICursor cursor = (ICursor)c_loader.LoadInBackground(); if (cursor.MoveToFirst()) { do { kayitlar.Add(new Kayit { Tarih = suankiZaman(long.Parse(cursor.GetString(cursor.GetColumnIndex(CallLog.Calls.Date)))).ToString(), Numara = cursor.GetString(cursor.GetColumnIndex(CallLog.Calls.Number)).ToString(), Durasyon = durasyon(cursor.GetString(cursor.GetColumnIndex(CallLog.Calls.Duration))), Tip = tur(cursor.GetString(cursor.GetColumnIndex(CallLog.Calls.Type))), }); } while (cursor.MoveToNext()); } } catch (Exception) { } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.HomeScreen); listView = FindViewById <ListView>(Resource.Id.List); string[] projection = new string[] { VegetableProvider.InterfaceConsts.Id, VegetableProvider.InterfaceConsts.Name }; string[] fromColumns = new string[] { VegetableProvider.InterfaceConsts.Name }; int[] toControlIds = new int[] { Android.Resource.Id.Text1 }; // ManagedQuery is deprecated in Honeycomb (3.0, API11) cursor = ManagedQuery(VegetableProvider.CONTENT_URI, projection, null, null, null); // ContentResolver requires you to close the query yourself //cursor = ContentResolver.Query(VegetableProvider.CONTENT_URI, projection, null, null, null); //StartManagingCursor(cursor); // CursorLoader introduced in Honeycomb (3.0, API11) var loader = new CursorLoader(this, VegetableProvider.CONTENT_URI, projection, null, null, null); cursor = (ICursor)loader.LoadInBackground(); // create a SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, Android.Resource.Layout.SimpleListItem1, cursor, fromColumns, toControlIds); listView.Adapter = adapter; listView.ItemClick += OnListItemClick; }
void FillContacts() { var uri = ContactsContract.Contacts.ContentUri; string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts.PhotoUri }; // CursorLoader introduced in Honeycomb (3.0, API11) var loader = new CursorLoader(this, uri, projection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); var contactImage = FindViewById <ImageView>(Resource.Id.imageView1); if (cursor.MoveToFirst()) { do { Console.WriteLine($"Id = {cursor.GetLong(cursor.GetColumnIndex(projection[0]))}"); Console.WriteLine($"DisplayName = {cursor.GetString(cursor.GetColumnIndex(projection[1]))}"); Console.WriteLine($"PhotoId = {cursor.GetString(cursor.GetColumnIndex(projection[2]))}"); if (cursor.GetString(cursor.GetColumnIndex(projection[2])) != null) { Android.Net.Uri urireal = Android.Net.Uri.Parse(cursor.GetString(cursor.GetColumnIndex(projection[2]))); contactImage.SetImageURI(urireal); } } while (cursor.MoveToNext()); } }
public static List <Song> LoadSongs(Activity context) { var uri = MediaStore.Audio.Media.ExternalContentUri; String selection = MediaStore.Audio.Media.InterfaceConsts.IsMusic + " != 0"; string[] projection = { MediaStore.Audio.Media.InterfaceConsts.Id, MediaStore.Audio.Albums.InterfaceConsts.AlbumId, MediaStore.Audio.Media.InterfaceConsts.Title, MediaStore.Audio.Media.InterfaceConsts.Artist, }; var loader = new CursorLoader(context, uri, projection, selection, null, null); var cursor = (ICursor)loader.LoadInBackground(); List <Song> songs = new List <Song> (); if (cursor.MoveToFirst()) { do { songs.Add(new Song( cursor.GetLong(cursor.GetColumnIndex(projection [0])), cursor.GetLong(cursor.GetColumnIndex(projection [1])), cursor.GetString(cursor.GetColumnIndex(projection [2])), cursor.GetString(cursor.GetColumnIndex(projection [3])) )); } while (cursor.MoveToNext()); } return(songs); }
void FillContacts() { var uri = ContactsContract.Contacts.ContentUri; string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id, ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.Contacts.InterfaceConsts.PhotoId }; // ManagedQuery is deprecated in Honeycomb (3.0, API11) //var cursor = activity.ManagedQuery (uri, projection, null, null, null); // ContentResolver requires you to close the query yourself //var cursor = activity.ContentResolver.Query(uri, projection, null, null, null); // CursorLoader introduced in Honeycomb (3.0, API11) var loader = new CursorLoader(activity, uri, projection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); contactList = new List <Contact> (); if (cursor.MoveToFirst()) { do { contactList.Add(new Contact { Id = cursor.GetLong(cursor.GetColumnIndex(projection [0])), DisplayName = cursor.GetString(cursor.GetColumnIndex(projection [1])), PhotoId = cursor.GetString(cursor.GetColumnIndex(projection [2])) }); } while (cursor.MoveToNext()); } }
public Loader <ICursor> OnCreateLoader(int id, Bundle args) { CursorLoader cl = new CursorLoader(GetActivity(), MainTable.CONTENT_URI, PROJECTION, null, null, null); cl.SetUpdateThrottle(2000); // update at most every 2 seconds. return(cl); }
public int IdByUri(Uri uri) { var loader = new CursorLoader(_context, uri, null, null, null, null); ICursor cur; cur = (ICursor)loader.LoadInBackground(); cur.MoveToFirst(); return(cur.GetInt(cur.GetColumnIndex(ContactsContract.Contacts.InterfaceConsts.Id))); }
// Convert a gallery URI to a regular file path private string GetPath(Android.Net.Uri uri) { string[] projection = new string[] { MediaStore.MediaColumns.Data }; CursorLoader loader = new CursorLoader(Activity, uri, projection, null, null, null); ICursor cursor = (ICursor)loader.LoadInBackground(); int column_index = cursor.GetColumnIndexOrThrow(MediaStore.MediaColumns.Data); cursor.MoveToFirst(); return(cursor.GetString(column_index)); }
public void LoadAndMergeTodaysItems(ObservableCollection <IToDoItem> toDo, ObservableCollection <IToDoItem> toDone) { var loader = new CursorLoader(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, CalendarContract.Calendars.ContentUri, calendarProjection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); if (!cursor.MoveToFirst()) { return; } do { var calID = cursor.GetLong(0); var calName = cursor.GetString(1); var accName = cursor.GetString(2); var ownerAcct = cursor.GetString(3); if (!(calName == accName && calName == ownerAcct)) { continue; } // query today var startTime = Calendar.Instance; var now = DateTime.Now; startTime.Set(now.Year, now.Month - 1, now.Day, 0, 0, 0); var endTime = Calendar.Instance; endTime.Set(now.Year, now.Month - 1, now.Day, 23, 59, 59); var contentUriStr = $"content://com.android.calendar/instances/when/{startTime.TimeInMillis}/{endTime.TimeInMillis}/"; var contentUri = AndUri.Parse(contentUriStr); var eventLoader = new CursorLoader(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, contentUri, eventProjection, null, null, null ); var eventCursor = (ICursor)eventLoader.LoadInBackground(); if (!eventCursor.MoveToFirst()) { return; } do { var eventId = eventCursor.GetLong(0); var eventTitle = eventCursor.GetString(1); if (eventTitle.StartsWith(kToDoPrefix, StringComparison.Ordinal)) { AddOrMerge(new ToDoItem(calID, eventId, TrimmedTitle(eventTitle)), toDo, toDone); } } while (eventCursor.MoveToNext()); } while (cursor.MoveToNext()); }
public void GetAllRecentContactHistory() { var uri = CallLog.Calls.ContentUri; string[] projection = { CallLog.Calls.Number, CallLog.Calls.Date, CallLog.Calls.Duration, CallLog.Calls.Type }; var loader = new CursorLoader(activity, uri, projection, null, null, null); try { var cursor = (ICursor)loader.LoadInBackground(); contactList = new List <Contact>(); if (cursor.MoveToFirst()) { do { Contact contact = new Contact { Number = cursor.GetString(cursor.GetColumnIndex(projection[0])).ToString(), Date = DateTime.FromOADate(ToTime(cursor.GetLong(cursor.GetColumnIndex(projection[1])).ToString())), Duration = cursor.GetString(cursor.GetColumnIndex(projection[2])), Type = cursor.GetString(cursor.GetColumnIndex(projection[3])), }; if (contact.Type.Equals("1")) { contact.Type = "Incoming"; } if (contact.Type.Equals("2")) { contact.Type = "Outgoing"; } if (contact.Type.Equals("3")) { contact.Type = "Missed"; } if (contact.Type.Equals("5")) { contact.Type = "Rejected"; } contactList.Add(contact); } while (cursor.MoveToNext()); } } catch { Thread.Sleep(500); GetAllRecentContactHistory(); } }
private ICursor CreateCursor() { string[] columns = { MediaStore.Images.Media.InterfaceConsts.Data, MediaStore.Images.Media.InterfaceConsts.Id }; string orderBy = MediaStore.Images.Media.InterfaceConsts.Id; var loader = new CursorLoader(this, MediaStore.Images.Media.ExternalContentUri, columns, null, null, orderBy + " DESC"); var cursor = (ICursor)loader.LoadInBackground(); return(cursor); }
public System.String NameByUri(Uri uri) { var loader = new CursorLoader(_context, uri, null, null, null, null); ICursor cur; cur = (ICursor)loader.LoadInBackground(); cur.MoveToFirst(); return(cur.GetString(cur.GetColumnIndex(ContactsContract.Contacts.InterfaceConsts.DisplayName))); }
private String GetRealPathFromUri(Context context, Uri uri) { String[] proj = { MediaStore.Images.ImageColumns.Data }; CursorLoader loader = new CursorLoader(context, uri, proj, null, null, null); ICursor cursor = (ICursor)loader.LoadInBackground(); int columnIndex = cursor.GetColumnIndexOrThrow(MediaStore.Images.ImageColumns.Data); cursor.MoveToFirst(); String result = cursor.GetString(columnIndex); cursor.Close(); return(result); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.CalendarList); // List Calendars var calendarsUri = CalendarContract.Calendars.ContentUri; string[] calendarsProjection = { CalendarContract.Calendars.InterfaceConsts.Id, CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, CalendarContract.Calendars.InterfaceConsts.AccountName }; var loader = new CursorLoader(this, calendarsUri, calendarsProjection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); string[] sourceColumns = { CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, CalendarContract.Calendars.InterfaceConsts.AccountName }; int[] targetResources = { Resource.Id.calDisplayName, Resource.Id.calAccountName }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, Resource.Layout.CalListItem, cursor, sourceColumns, targetResources); ListAdapter = adapter; ListView.ItemClick += (sender, e) => { int i = (e as Android.Widget.AdapterView.ItemClickEventArgs).Position; cursor.MoveToPosition(i); int calId = cursor.GetInt(cursor.GetColumnIndex(calendarsProjection [0])); var showEvents = new Intent(this, typeof(EventListActivity)); showEvents.PutExtra("calId", calId); StartActivity(showEvents); }; }
private string CreateCursor() { string[] columns = { MediaStore.Images.Media.InterfaceConsts.Data, MediaStore.Images.Media.InterfaceConsts.Id }; string orderBy = MediaStore.Images.Media.InterfaceConsts.Id; Console.WriteLine("Creating cursor"); //_imagecursor = ManagedQuery(MediaStore.Images.Media.ExternalContentUri, columns, null, null, orderBy + " DESC"); var loader = new CursorLoader(this, MediaStore.Images.Media.ExternalContentUri, columns, null, null, orderBy + " DESC"); _imagecursor = (ICursor)loader.LoadInBackground(); return(orderBy); }
//@SuppressLint("NewApi") public static String GetRealPathFromURI_API11to18(Context context, Uri contentUri) { String[] proj = { MediaStore.Images.Media.InterfaceConsts.Data }; String result = null; CursorLoader cursorLoader = new CursorLoader(context, contentUri, proj, null, null, null); ICursor cursor = (ICursor)cursorLoader.LoadInBackground(); if (cursor != null) { int column_index = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Data); cursor.MoveToFirst(); result = cursor.GetString(column_index); cursor.Close(); } return(result); }
private static string getRealPathFromUri_Api11To18(Context context, Android.Net.Uri uri) { string filePath = null; string[] projection = { Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data }; //这个有两个包不知道是哪个。。。。不过这个复杂版一般用不到 CursorLoader loader = new CursorLoader(context, uri, projection, null, null, null); var cursor = loader.LoadInBackground() as Android.Database.ICursor; if (cursor != null) { cursor.MoveToFirst(); filePath = cursor.GetString(cursor.GetColumnIndex(projection[0])); cursor.Close(); } return(filePath); }
public string AddEvent(string Title, string Description, DateTime StartDate, DateTime EndDate, string StartTimeZone, string EndTimeZone) { //Getting available calendars var calendarsUri = CalendarContract.Calendars.ContentUri; string[] calendarsProjection = { CalendarContract.Calendars.InterfaceConsts.Id, CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, CalendarContract.Calendars.InterfaceConsts.AccountName }; var loader = new CursorLoader(Forms.Context, calendarsUri, calendarsProjection, null, null, null); var cursor = (ICursor)loader.LoadInBackground(); if (!cursor.MoveToFirst()) { return("You don't have any calendar"); } int calId = cursor.GetInt(cursor.GetColumnIndex(calendarsProjection[0])); ContentValues eventValues = new ContentValues(); eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, calId); eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, Title); eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, Description); eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(StartDate.Year, StartDate.Month, StartDate.Day, StartDate.Hour, StartDate.Minute)); eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(EndDate.Year, EndDate.Month, EndDate.Day, EndDate.Hour, EndDate.Minute)); eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, StartTimeZone); //UTC eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, EndTimeZone); //UTC var uri = Forms.Context.ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues); return("event added"); }
/// <summary> /// Get the real file path from URI registered in media store /// </summary> /// <param name="contentUri"> /// URI registered in media store </param> public static string getRealPathFromURI(Activity activity, Uri contentUri) { string releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS Version */ if (releaseNumber.Length > 0 && releaseNumber[0] == '4') { string[] proj = new string[] {MediaStore.Images.Media.DATA}; string strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); if (cursorLoader != null) { Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.Count > 0) { strFileName = cursor.getString(column_index); } cursor.close(); } } return strFileName; } /* GB Version */ else if (releaseNumber.StartsWith("2.3", StringComparison.Ordinal)) { string[] proj = new string[] {MediaStore.Images.Media.DATA}; string strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.Count > 0) { strFileName = cursor.getString(column_index); } cursor.close(); } return strFileName; } } // --------------------- // Undefined Version // --------------------- /* GB, ICS Common */ string[] proj = new string[] {MediaStore.Images.Media.DATA}; string strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.Count > 0) { strFileName = cursor.getString(column_index); } // cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }