Пример #1
0
        private void Check_Timer_Tick(object state)
        {
            if (IsPermission && this.cursor != null)
            {
                string mmsId  = string.Empty;
                Coupon coupon = null;

                List <int> cursors = new List <int>();
                int        point   = -1;

                for (int i = 0; i < cursor.Count && cursor != null; i++)
                {
                    if (cursor.MoveToFirst())
                    {
                        cursor.Move(i);
                        string tmp = cursor.GetString(cursor.GetColumnIndex("_id"));
                        if (!string.IsNullOrWhiteSpace(tmp))
                        {
                            if (int.TryParse(tmp, out point))
                            {
                                cursors.Add(point);
                            }
                        }
                    }
                }

                if (cursors != null && cursors.Count > 0)
                {
                    point = cursors.Max();

                    if (point > 0)
                    {
                        mmsId = Convert.ToString(point);
                        Keys.TryAdd(mmsId, false);
                        Android.Net.Uri uri       = Android.Net.Uri.Parse($"content://{Mode}/part");
                        string          selection = "_id=" + mmsId;
                        var             query     = ContentResolver.Query(uri, null, selection, null, null);
                        if (query.MoveToFirst())
                        {
                            do
                            {
                                try
                                {
                                    coupon             = new Coupon();
                                    coupon.ID          = query.GetString(query.GetColumnIndex("_id"));
                                    coupon.ReceiveType = query.GetString(query.GetColumnIndex("ct"));
                                    coupon.Phone       = getPhone(coupon.ID).Trim();

                                    string data = query.GetString(query.GetColumnIndex("_data"));
                                    if (data != null)
                                    {
                                        coupon.Body = getMmsText(coupon.ID);
                                    }
                                    else
                                    {
                                        coupon.Body = query.GetString(query.GetColumnIndex("text"));
                                    }

                                    Values.AddOrUpdate(mmsId, coupon, (x, y) => coupon);
                                }
                                catch
                                {
                                }
                            } while (query.MoveToNext());
                        }
                    }
                }

                workTimer = new Timer(Work_Timer_Tick, null, 1000, Timeout.Infinite);
            }
        }