Does anybody know what data structures are used to the store messages in an SMS client app, and whether there is an existing API for this.
I was perhaps looking at implementing a link list for the purpose but if the work has already been done in an API then perhaps it would be unnecess开发者_Go百科ary to commit time to the task that could be spent programming other parts.
Many thanks
In android there is android.telephony.SmsMessage. This is the object used within android to store a single SMS message. You can look at that and build something that resembles it, or reuse it.
As far as the data structure for storing them, I would suggest you use a java.util.List<E>, which gives you much more flexibility over some of the other data structures, like a standard array[].
If you're looking at storing your SMS messages over a longer period of time, then I would also suggest you take a look at persistence using SQLlite, which is also a part of the Android platform.
As for the built-in Messaging app, it's storing all the messages in a database. You can check out the Android source code to see what it does, but I would recommending against reading this data - it's not part of the official SDK, so it might change, or some phones might not have it.
As for storing it yourself - I wouldn't use a linked list. Use a database, that's the preferred way to store any persistent data (other than little individual values, for which you use SharedPreferences).
Uri uriSMS=Uri.parse("Content://sms/inbox");
Cursor cur=getContentResolver().query(uriSMS,null,null,null,null);
String[] sender=new String[100];String[] content=new String[100];int ct=0;
While(cur.moveToNext()){
sender[ct]=cur.getString(2);//arg2: this is address
content[ct]=cur.getString(11);//arg11: this is body of SMS
//[0: _id,1: thread_id,2: address,3: person,4: date,5: protocol,6: read,7: status,8: type,9: reply_path_present,10: subject,11: body,12: service_center,13: locked,14: error_code,15: seen]
}
This is structure of content in SMS, for example, I get arg2 and arg11 this is the address and content of sms. Using this sample, you can read all of SMS stored in phone
加载中,请稍侯......
精彩评论