Beispiel #1
0
        private void GetSMSMessages()
        {
            var cursor = Application.Context.ContentResolver.Query(Telephony.Sms.Inbox.ContentUri, null, null, null, null);
            //Application.Context.ContentResolver.Query(Android.Net.Uri.Parse("content://sms/inbox"), null, null, null, null);

            var SMS = new List <MessageObject>();

            if (cursor.MoveToFirst())
            {
                //Console.WriteLine("ID LIST:");
                do
                {
                    var    ID   = cursor.GetString(cursor.GetColumnIndex(Telephony.Sms.Inbox.InterfaceConsts.Id));
                    string From = cursor.GetString(cursor.GetColumnIndex(Telephony.Sms.Inbox.InterfaceConsts.Address)).ToString();
                    //string From = getContactName(cursor.GetString(cursor.GetColumnIndex(Telephony.Sms.Inbox.InterfaceConsts.Address)).ToString());
                    //string Creator = cursor.GetString(cursor.GetColumnIndex(Telephony.Sms.Inbox.InterfaceConsts.Address)).ToString();
                    string messageVal = cursor.GetString(cursor.GetColumnIndex(Telephony.Sms.Inbox.InterfaceConsts.Body)).ToString();

                    var epoch   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);
                    var Dateval = epoch.AddMilliseconds(cursor.GetLong(cursor.GetColumnIndex(Telephony.Sms.Inbox.InterfaceConsts.Date))).AddHours(10);
                    var currSMS = new MessageObject(ID, From, messageVal, Dateval);
                    SMS.Add(currSMS);
                } while (cursor.MoveToNext());
            }
            cursor.Close();

            var eListAdapt = new SMSListAdapter(this, SMS);

            eListAdapt.NotifyDataSetChanged();

            var SMSListView = FindViewById <ListView>(Resource.Id.lvSMSList);

            SMSListView.Adapter = eListAdapt;
        }
Beispiel #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.MessageForm);
            isRecording = false;

            //initialize speech to text (input)
            InitSTTMethod();
            //initialize text to speech (read/speak)
            InitTTSMethod();

            var backButton = FindViewById <Button>(Resource.Id.btnBackSMSForm);

            backButton.Click += delegate { Finish(); };

            var btnGetMessages = FindViewById <Button>(Resource.Id.btnGetSMSMessageForm);

            btnGetMessages.Click += delegate
            {
                var progressDialog = ProgressDialog.Show(this, "Please wait...", "Fetching Messages", true);
                progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
                new Thread(new ThreadStart(delegate
                {
                    //LOAD METHOD TO GET ACCOUNT INFO
                    RunOnUiThread(() => {
                        Toast.MakeText(this, "SMS Sync: Fetching Messages", ToastLength.Long).Show();
                    });
                    RunOnUiThread(() => GetSMSMessages());
                    //GetSMSMessages();
                    RunOnUiThread(() => {
                        Toast.MakeText(this, "SMS Sync: Successful", ToastLength.Long).Show();
                    });

                    //HIDE PROGRESS DIALOG
                    RunOnUiThread(() => progressDialog.Hide());
                })).Start();
            };

            var btnResetSMSMessageForm = FindViewById <Button>(Resource.Id.btnResetSMSMessageForm);

            btnResetSMSMessageForm.Click += delegate
            {
                smsTOValue     = "";
                smsBodyValue   = "";
                smsConfirmSend = "";
                NeedToSpeak    = true;
                //this.OnCreate(null);
                Finish();
                StartActivity(typeof(MessageActivity));
            };

            var lvSMS = FindViewById <ListView>(Resource.Id.lvSMSList);

            lvSMS.ItemClick += (sender, e) => {
                SMSListAdapter SMSList = ((SMSListAdapter)lvSMS.Adapter);
                MessageObject  item    = SMSList[e.Position];

                var actSMSReader = new Intent(this, typeof(MessageReaderActivity));
                actSMSReader.PutExtra("SMSFrom", item.From);
                actSMSReader.PutExtra("SMSID", item.MessageID);
                actSMSReader.PutExtra("SMSDate", item.Date.ToString());
                actSMSReader.PutExtra("SMSMessage", item.Message);
                actSMSReader.PutExtra("curPos", e.Position);
                actSMSReader.PutExtra("maxPos", ((SMSListAdapter)lvSMS.Adapter).Count);
                actSMSReader.PutExtra("autoRead", 1);
                actSMSReader.SetFlags(ActivityFlags.ReorderToFront);
                StartActivity(actSMSReader);
            };

            ActivityStatus = "Created";

            GetSMSMessages();
        }