943,102 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1590
  • C# RSS
Feb 8th, 2010
0

retrieve SMS from a mobile phone

Expand Post »
As a part of my final year project i need to make a system to retrieve sms's on a mobile phone(lets say only symbian phones only).i created a app and the thing is it is not working.so if any one know about this plz make a ryply

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6.  
  7. using System.Data;
  8.  
  9. using GsmComm.PduConverter;
  10. using GsmComm.GsmCommunication;
  11.  
  12. namespace SMS
  13. {
  14. /// <summary>
  15. /// Summary description for Receive.
  16. /// </summary>
  17. public class Receive : System.Windows.Forms.Form
  18. {
  19. private System.Windows.Forms.Button btnReadMessage;
  20. private System.Windows.Forms.RadioButton rbMessagePhone;
  21. private System.Windows.Forms.RadioButton rbMessageSIM;
  22. private System.Windows.Forms.TextBox txtOutput;
  23. private System.Windows.Forms.GroupBox groupBox1;
  24. private System.Windows.Forms.DataGrid dataGrid1;
  25. /// <summary>
  26. /// Required designer variable.
  27. /// </summary>
  28. private System.ComponentModel.Container components = null;
  29. private DataTable dt=new DataTable();
  30. private delegate void SetTextCallback(string text);
  31.  
  32. public Receive()
  33. {
  34. //
  35. // Required for Windows Form Designer support
  36. //
  37. InitializeComponent();
  38.  
  39. //
  40. // TODO: Add any constructor code after InitializeComponent call
  41. //
  42. }
  43.  
  44. /// <summary>
  45. /// Clean up any resources being used.
  46. /// </summary>
  47. protected override void Dispose( bool disposing )
  48. {
  49. if( disposing )
  50. {
  51. if(components != null)
  52. {
  53. components.Dispose();
  54. }
  55. }
  56. base.Dispose( disposing );
  57. }
  58.  
  59. #region Windows Form Designer generated code
  60. /// <summary>
  61. /// Required method for Designer support - do not modify
  62. /// the contents of this method with the code editor.
  63. /// </summary>
  64. private void InitializeComponent()
  65. {
  66. this.btnReadMessage = new System.Windows.Forms.Button();
  67. this.rbMessagePhone = new System.Windows.Forms.RadioButton();
  68. this.rbMessageSIM = new System.Windows.Forms.RadioButton();
  69. this.txtOutput = new System.Windows.Forms.TextBox();
  70. this.groupBox1 = new System.Windows.Forms.GroupBox();
  71. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  72. this.groupBox1.SuspendLayout();
  73. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  74. this.SuspendLayout();
  75. //
  76. // btnReadMessage
  77. //
  78. this.btnReadMessage.FlatStyle = System.Windows.Forms.FlatStyle.System;
  79. this.btnReadMessage.Location = new System.Drawing.Point(192, 80);
  80. this.btnReadMessage.Name = "btnReadMessage";
  81. this.btnReadMessage.Size = new System.Drawing.Size(112, 24);
  82. this.btnReadMessage.TabIndex = 17;
  83. this.btnReadMessage.Text = "Read All Messages";
  84. this.btnReadMessage.Click += new System.EventHandler(this.btnReadMessage_Click);
  85. //
  86. // rbMessagePhone
  87. //
  88. this.rbMessagePhone.FlatStyle = System.Windows.Forms.FlatStyle.System;
  89. this.rbMessagePhone.Location = new System.Drawing.Point(16, 56);
  90. this.rbMessagePhone.Name = "rbMessagePhone";
  91. this.rbMessagePhone.Size = new System.Drawing.Size(64, 24);
  92. this.rbMessagePhone.TabIndex = 25;
  93. this.rbMessagePhone.Text = "Phone";
  94. //
  95. // rbMessageSIM
  96. //
  97. this.rbMessageSIM.Checked = true;
  98. this.rbMessageSIM.FlatStyle = System.Windows.Forms.FlatStyle.System;
  99. this.rbMessageSIM.Location = new System.Drawing.Point(16, 24);
  100. this.rbMessageSIM.Name = "rbMessageSIM";
  101. this.rbMessageSIM.Size = new System.Drawing.Size(64, 24);
  102. this.rbMessageSIM.TabIndex = 24;
  103. this.rbMessageSIM.TabStop = true;
  104. this.rbMessageSIM.Text = "SIM";
  105. //
  106. // txtOutput
  107. //
  108. this.txtOutput.Location = new System.Drawing.Point(8, 304);
  109. this.txtOutput.Multiline = true;
  110. this.txtOutput.Name = "txtOutput";
  111. this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
  112. this.txtOutput.Size = new System.Drawing.Size(448, 144);
  113. this.txtOutput.TabIndex = 57;
  114. this.txtOutput.Text = "";
  115. //
  116. // groupBox1
  117. //
  118. this.groupBox1.Controls.Add(this.rbMessageSIM);
  119. this.groupBox1.Controls.Add(this.rbMessagePhone);
  120. this.groupBox1.Location = new System.Drawing.Point(8, 8);
  121. this.groupBox1.Name = "groupBox1";
  122. this.groupBox1.Size = new System.Drawing.Size(176, 96);
  123. this.groupBox1.TabIndex = 58;
  124. this.groupBox1.TabStop = false;
  125. this.groupBox1.Text = "Message Storage";
  126. //
  127. // dataGrid1
  128. //
  129. this.dataGrid1.DataMember = "";
  130. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  131. this.dataGrid1.Location = new System.Drawing.Point(8, 120);
  132. this.dataGrid1.Name = "dataGrid1";
  133. this.dataGrid1.Size = new System.Drawing.Size(448, 176);
  134. this.dataGrid1.TabIndex = 59;
  135. //
  136. // Receive
  137. //
  138. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  139. this.ClientSize = new System.Drawing.Size(464, 454);
  140. this.Controls.Add(this.dataGrid1);
  141. this.Controls.Add(this.groupBox1);
  142. this.Controls.Add(this.txtOutput);
  143. this.Controls.Add(this.btnReadMessage);
  144. this.Name = "Receive";
  145. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  146. this.Text = "Read Messages";
  147. this.Load += new System.EventHandler(this.Receive_Load);
  148. this.groupBox1.ResumeLayout(false);
  149. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  150. this.ResumeLayout(false);
  151.  
  152. }
  153. #endregion
  154.  
  155. private void btnReadMessage_Click(object sender, System.EventArgs e)
  156. {
  157. Cursor.Current = Cursors.WaitCursor;
  158. string storage = GetMessageStorage();
  159.  
  160. try
  161. {
  162. // Read all SMS messages from the storage
  163.  
  164. DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage);
  165. foreach(DecodedShortMessage message in messages)
  166. {
  167. Output(string.Format("Message status = {0}, Location = {1}/{2}",
  168. StatusToString(message.Status), message.Storage, message.Index));
  169. ShowMessage(message.Data);
  170. Output("");
  171. }
  172. Output(string.Format("{0,9} messages read.", messages.Length.ToString()));
  173. Output("");
  174. }
  175. catch(Exception ex)
  176. {
  177. MessageBox.Show(ex.Message);
  178. }
  179.  
  180. Cursor.Current = Cursors.Default;
  181. }
  182.  
  183.  
  184. private void BindGrid(SmsPdu pdu)
  185. {
  186.  
  187. DataRow dr=dt.NewRow();
  188. SmsDeliverPdu data = (SmsDeliverPdu)pdu;
  189.  
  190. dr[0]=data.OriginatingAddress.ToString();
  191. dr[1]=data.SCTimestamp.ToString();
  192. dr[2]=data.UserDataText;
  193. dt.Rows.Add(dr);
  194.  
  195. dataGrid1.DataSource=dt;
  196. }
  197.  
  198. private void ShowMessage(SmsPdu pdu)
  199. {
  200. if (pdu is SmsSubmitPdu)
  201. {
  202. // Stored (sent/unsent) message
  203. SmsSubmitPdu data = (SmsSubmitPdu)pdu;
  204. Output("SENT/UNSENT MESSAGE");
  205. Output("Recipient: " + data.DestinationAddress);
  206. Output("Message text: " + data.UserDataText);
  207. Output("-------------------------------------------------------------------");
  208. return;
  209. }
  210. if (pdu is SmsDeliverPdu)
  211. {
  212. // Received message
  213. SmsDeliverPdu data = (SmsDeliverPdu)pdu;
  214. Output("RECEIVED MESSAGE");
  215. Output("Sender: " + data.OriginatingAddress);
  216. Output("Sent: " + data.SCTimestamp.ToString());
  217. Output("Message text: " + data.UserDataText);
  218. Output("-------------------------------------------------------------------");
  219.  
  220. BindGrid(pdu);
  221.  
  222. return;
  223. }
  224. if (pdu is SmsStatusReportPdu)
  225. {
  226. // Status report
  227. SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
  228. Output("STATUS REPORT");
  229. Output("Recipient: " + data.RecipientAddress);
  230. Output("Status: " + data.Status.ToString());
  231. Output("Timestamp: " + data.DischargeTime.ToString());
  232. Output("Message ref: " + data.MessageReference.ToString());
  233. Output("-------------------------------------------------------------------");
  234. return;
  235. }
  236. Output("Unknown message type: " + pdu.GetType().ToString());
  237. }
  238.  
  239.  
  240. private string StatusToString(PhoneMessageStatus status)
  241. {
  242. // Map a message status to a string
  243. string ret;
  244. switch(status)
  245. {
  246. case PhoneMessageStatus.All:
  247. ret = "All";
  248. break;
  249. case PhoneMessageStatus.ReceivedRead:
  250. ret = "Read";
  251. break;
  252. case PhoneMessageStatus.ReceivedUnread:
  253. ret = "Unread";
  254. break;
  255. case PhoneMessageStatus.StoredSent:
  256. ret = "Sent";
  257. break;
  258. case PhoneMessageStatus.StoredUnsent:
  259. ret = "Unsent";
  260. break;
  261. default:
  262. ret = "Unknown (" + status.ToString() + ")";
  263. break;
  264. }
  265. return ret;
  266. }
  267.  
  268.  
  269. private string GetMessageStorage()
  270. {
  271. string storage = string.Empty;
  272. if (rbMessageSIM.Checked)
  273. storage = PhoneStorageType.Sim;
  274. if (rbMessagePhone.Checked)
  275. storage = PhoneStorageType.Phone;
  276. if (storage.Length == 0)
  277. throw new ApplicationException("Unknown message storage.");
  278. else
  279. return storage;
  280. }
  281.  
  282.  
  283. private void Output(string text)
  284. {
  285. if (this.txtOutput.InvokeRequired)
  286. {
  287. SetTextCallback stc = new SetTextCallback(Output);
  288. this.Invoke(stc, new object[] { text });
  289. }
  290. else
  291. {
  292. txtOutput.AppendText(text);
  293. txtOutput.AppendText("\r\n");
  294. }
  295. }
  296.  
  297.  
  298. private void Receive_Load(object sender, System.EventArgs e)
  299. {
  300. dt.Columns.Add("Sender",typeof(string));
  301. dt.Columns.Add("Time",typeof(string));
  302. dt.Columns.Add("Message",typeof(string));
  303. }
  304.  
  305. private void Output(string text, params object[] args)
  306. {
  307. string msg = string.Format(text, args);
  308. Output(msg);
  309. }
  310.  
  311. }
  312. }
Similar Threads
Reputation Points: 3
Solved Threads: 0
Junior Poster
chathuD is offline Offline
128 posts
since Jul 2009
Apr 2nd, 2010
0

Handling Picture or non-supported text sms

Click to Expand / Collapse  Quote originally posted by chathuD ...
C# Syntax (Toggle Plain Text)
  1.  
  2. private void BindGrid(SmsPdu pdu)
  3. {
  4.  
  5. DataRow dr=dt.NewRow();
  6. SmsDeliverPdu data = (SmsDeliverPdu)pdu;
  7.  
  8. dr[0]=data.OriginatingAddress.ToString();
  9. dr[1]=data.SCTimestamp.ToString();
  10. dr[2]=data.UserDataText;
  11. dt.Rows.Add(dr);
  12.  
  13. dataGrid1.DataSource=dt;
  14. }
Here, we see that it is only handling text sms, what about the Picture messages? What about the text which is not supported by 7-bit charset?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aatif is offline Offline
1 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Dynamic return types
Next Thread in C# Forum Timeline: focus end textbox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC