public bool SendMessage(long threadId, string message, string phoneAddr) { try { if (!string.IsNullOrEmpty(phoneAddr)) { SmsManager sm = SmsManager.Default; List <string> parts = new List <string>(4); if (message.Length <= 160) { parts.Add(message); } else { parts = BreakMessageIntoParts(message, 140); } sm.SendMultipartTextMessage(phoneAddr, null, parts, null, null); } } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); return(false); } return(true); }
public override void OnReceive(Context context, Intent intent) { //MMS WAP_PUSH_RECEIVED if (Telephony.Sms.Intents.WapPushReceivedAction.Equals(intent.Action)) { List <Model.SmsMessage> msgLst = null; // since we cannot directly read the MMS message here, we have to query the db and see if we can get the message out of the db if (null != MobileGlobals.SmsProviderInst) { msgLst = MobileGlobals.SmsProviderInst.GetLastMmsMessage(); } if (null != MobileGlobals.NotifyNewSmsMessageArrivedCallback && null != msgLst) { foreach (Model.SmsMessage msg in msgLst) { MobileGlobals.NotifyNewSmsMessageArrivedCallback(msg); } } } //MMS WAP_PUSH_DELIVER if (Telephony.Sms.Intents.WapPushDeliverAction.Equals(intent.Action)) { // TODO } }
public byte[] GetMMSPduData(string phone, string imgFilePath, string txtMessage) { Context ctx = AndroidGlobals.MainActivity; byte[] pduData = null; try { if (!string.IsNullOrEmpty(phone) && (!string.IsNullOrEmpty(imgFilePath) || !string.IsNullOrEmpty(txtMessage))) { ///////////////////PDU Management Method/////////////////////////////////////////////////////// // First instantiate the PDU we will be turning into a byte array that // will be ultimately sent to the MMS service provider. // In this case, we are using a SendReq PDU type. SendReq sendReqPdu = new SendReq(); // Set the recipient number of our MMS sendReqPdu.AddTo(new EncodedStringValue(phone)); // Instantiate the body of our MMS PduBody pduBody = new PduBody(); // Add any text message data if (!string.IsNullOrEmpty(txtMessage)) { PduPart txtPart = new PduPart(); txtPart.SetData(Encoding.ASCII.GetBytes(txtMessage)); txtPart.SetContentType(new EncodedStringValue("text/plain").GetTextString()); txtPart.SetName(new EncodedStringValue("Message").GetTextString()); pduBody.AddPart(txtPart); } // add any image data if (!string.IsNullOrEmpty(imgFilePath)) { PduPart imgPart = new PduPart(); byte[] sampleImageData = GetFileBytes(imgFilePath); imgPart.SetData(sampleImageData); imgPart.SetContentType(new EncodedStringValue("image/png").GetTextString()); imgPart.SetFilename(new EncodedStringValue(System.IO.Path.GetFileName(imgFilePath)).GetTextString()); pduBody.AddPart(imgPart); } // Set the body of our MMS sendReqPdu.Body = pduBody; // Finally, generate the byte array to send to the MMS provider PduComposer composer = new PduComposer(sendReqPdu); pduData = composer.Make(); } } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } return(pduData); }
protected override void OnPause() { base.OnPause(); try { wakeLock.Release(); } catch { } if (null != MobileGlobals.NotifyPauseResume) { MobileGlobals.NotifyPauseResume(); } }
private string GetRealPathFromMediaStoreImageURI(Android.Net.Uri contentUri) { Context ctx = AndroidGlobals.MainActivity; try { if (string.IsNullOrEmpty(contentUri.LastPathSegment)) { return(null); } string[] idParts = contentUri.LastPathSegment.Split(new char[] { ':' }); if (idParts.Length < 2) { return(null); } string id = idParts[1]; Android.Net.Uri uri = MediaStore.Images.Media.ExternalContentUri; string selection = "_id=?"; string[] selArgs = new string[] { id }; var mediaStoreImagesMediaData = "_data"; string[] projection = { mediaStoreImagesMediaData }; Android.Database.ICursor cursor = this.ApplicationContext.ContentResolver.Query(uri, projection, selection, selArgs, null); if (null != cursor) { cursor.MoveToFirst(); return(cursor.GetString(0)); } } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } return(null); }
public bool SendMMSPduData(byte[] pduData) { Context ctx = AndroidGlobals.MainActivity.ApplicationContext; SmsManager sm = SmsManager.Default; Random rnd = new Random(); try { // write the pdu to a temp cache file string cacheFilePath = System.IO.Path.Combine(ctx.CacheDir.AbsolutePath, "send." + rnd.Next().ToString() + ".dat"); File.WriteAllBytes(cacheFilePath, pduData); if (File.Exists(cacheFilePath)) { // create the contentUri Android.Net.Uri contentUri = (new Android.Net.Uri.Builder()) .Authority(ctx.PackageName + ".fileprovider") .Path(cacheFilePath) .Scheme(ContentResolver.SchemeContent) .Build(); PendingIntent pendingIntent = PendingIntent.GetBroadcast(ctx, 0, new Intent(ctx.PackageName + ".WAP_PUSH_DELIVER"), 0); //sm.SendMultimediaMessage(ctx, contentUri, null, null, pendingIntent); sm.SendMultimediaMessage(ctx, contentUri, null, null, null); } } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); return(false); } return(true); }
public override void OnReceive(Context context, Intent intent) { // SMS_RECEIVED if (Telephony.Sms.Intents.SmsReceivedAction.Equals(intent.Action)) { Model.SmsMessage newMsg = null; string message = string.Empty; string phoneKey = null; SmsMessage[] messages = Telephony.Sms.Intents.GetMessagesFromIntent(intent); SmsMessage prevMsg = null; if (messages.Length > 0) { for (int i = 0; i < messages.Length; i++) { SmsMessage msg = messages[i]; if (null != prevMsg && msg.OriginatingAddress != prevMsg.OriginatingAddress) {// send the curren previous set if (null != MobileGlobals.NotifyNewSmsMessageArrivedCallback) { phoneKey = MobileGlobals.GeneratePhoneLookupKey(prevMsg.OriginatingAddress); DateTime now = DateTime.Now; newMsg = new Model.SmsMessage() { DateReceived = now, DateSent = now, ToFromPhoneAddress = prevMsg.OriginatingAddress, PhoneLookupKey = phoneKey, Message = message, ThreadId = -1 }; MobileGlobals.NotifyNewSmsMessageArrivedCallback(newMsg); } // reset the message message = string.Empty; } message += msg.MessageBody; if (messages.Length > 1 && i < messages.Length - 1) { message += " "; } prevMsg = msg; } } if (null != MobileGlobals.NotifyNewSmsMessageArrivedCallback && !string.IsNullOrEmpty(message)) { phoneKey = MobileGlobals.GeneratePhoneLookupKey(prevMsg.OriginatingAddress); DateTime now = DateTime.Now; newMsg = new Model.SmsMessage() { DateReceived = now, DateSent = now, ToFromPhoneAddress = prevMsg.OriginatingAddress, PhoneLookupKey = phoneKey, Message = message, ThreadId = -1 }; MobileGlobals.NotifyNewSmsMessageArrivedCallback(newMsg); } } // SMS_DELIVER_ACTION if (Telephony.Sms.Intents.SmsDeliverAction.Equals(intent.Action)) { // TODO } }
private void FinishLoadApp() { try { MobileGlobals.ApplicationDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); AndroidGlobals.MainActivity = this; MobileGlobals.CacheDirectory = AndroidGlobals.MainActivity.CacheDir.AbsolutePath; MobileGlobals.RootDir = Android.OS.Environment.RootDirectory.Path; MobileGlobals.SharedStorageDir = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; MobileGlobals.ExternalStorageDirRoot = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; MobileGlobals.ExternalStorageDirRemovableMusic = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMusic).AbsolutePath; MobileGlobals.ExternalStorageDirForAppUninstalled = AndroidGlobals.MainActivity.GetExternalFilesDir(null).AbsolutePath; MobileGlobals.AppDataPermanentStorageDir = MobileGlobals.ExternalStorageDirRoot + "/com.AndroidTest.Data"; if (!Directory.Exists(MobileGlobals.AppDataPermanentStorageDir)) { try { Directory.CreateDirectory(MobileGlobals.AppDataPermanentStorageDir); } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } } } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } // Get a Wakelock try { PowerManager powerManager = (PowerManager)this.GetSystemService(Context.PowerService); wakeLock = powerManager.NewWakeLock(WakeLockFlags.Full, "My Lock"); } catch (Exception ex) { MobileGlobals.AddNewException(ex); ex = new Exception("Error Getting PowerManager Wake Lock."); MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } try { LoadApplication(new App()); } catch (Exception ex) { MobileGlobals.AddNewException(ex); ex = new Exception("Error on LoadApplication() method."); MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } }