Back to project page sms_modi.
The source code is released under:
GNU General Public License
If you think the Android project sms_modi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.zhufeng.sms_mod; /*w w w . ja va2 s. c o m*/ import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; public class Sms_readActivity extends Activity { /* Called when the activity is first created. */ private static final String LOG_TAG = "Sms Query"; final String ADDRESS = "address"; // ????????????? final String DATE = "date"; final String READ = "read"; final String STATUS = "status"; final String BODY = "body"; // ?????? final String TYPE = "type"; // 1??????2?????? final String PERSON = "person"; // ???????????????? final String THREAD_ID = "thread_id"; int MESSAGE_TYPE_INBOX = 1; int MESSAGE_TYPE_SENT = 2; // ?????onCreate public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sms_read); TextView tv = new TextView(this); tv.setText("Hello, Android! \n\n"); tv.append(getSmsByContent(7025) + "\n\n"); // tv.append(getSmsByThreadID(1)); // ScrollView ???????child view ScrollView sv = new ScrollView(this); sv.addView(tv); setContentView(sv); // Toast.makeText(this, this.getString(R.string.toast_end), // Toast.LENGTH_LONG).show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } // ?thread_id???? @SuppressWarnings("deprecation") public String getSmsByThreadID(int thread_id) { StringBuilder str = new StringBuilder(); try { Cursor cs = managedQuery(Uri.parse("content://sms"), new String[] { ADDRESS, DATE, TYPE, BODY }, "thread_id = " + thread_id, null, "date desc"); str.append("?thread_id=" + thread_id + "?????????\n\n"); str.append("????????????????" + cs.getCount() + "\n\n"); str.append(processResults(cs, true)); str.append("getSmsByThreadID() has executed!"); // System.out.println("getSmsByThreadID() has executed!"); } catch (SQLiteException ex) { Log.d(LOG_TAG, ex.getMessage()); } Toast.makeText(this, this.getString(R.string.toast_getSmsByThreadID), Toast.LENGTH_LONG).show(); return str.toString(); } // ??????? @SuppressWarnings("deprecation") public String getSmsByContent(int number) { StringBuilder str = new StringBuilder(); try { Cursor myCursor = managedQuery(Uri.parse("content://sms"), new String[] { ADDRESS, BODY, DATE, TYPE }, "address like ?", new String[] { "%" + number + "%" }, "date desc"); str.append("?????????" + number + "?????????\n\n"); str.append("????????????????" + myCursor.getCount() + "\n\n"); str.append(processResults(myCursor, true)); str.append("getSmsByContent() has executed!"); // System.out.println("getSmsByContent has executed!"); } catch (SQLiteException ex) { Log.d(LOG_TAG, ex.getMessage()); } Toast.makeText(this, this.getString(R.string.toast_getSmsByContent), Toast.LENGTH_LONG).show(); return str.toString(); } /* * ???????? * * @param cur * * @param all ???????????????????????????all??????? */ private StringBuilder processResults(Cursor cur, boolean all) { StringBuilder str = new StringBuilder(); if (cur.moveToFirst()) { // String name; String phoneNumber; String sms; String date; String type; // int nameColumn = cur.getColumnIndex(PERSON); int addressColumn = cur.getColumnIndex(ADDRESS); int bodyColumn = cur.getColumnIndex(BODY); int dateColumn = cur.getColumnIndex(DATE); int typeColumn = cur.getColumnIndex(TYPE); do { // Get the field values // name = cur.getString(nameColumn); phoneNumber = cur.getString(addressColumn); sms = cur.getString(bodyColumn); date = DateFormatConv.convertDateFormat(cur .getString(dateColumn)); type = cur.getString(typeColumn); if (type.equals("1")) type = "??"; if (type.equals("2")) type = "?????"; str.append("{"); // str.append(name + ","); str.append(phoneNumber + " , "); str.append(date + " , "); str.append(type + " , "); str.append(sms); str.append("}"); str.append("\n\n"); if (null == sms) sms = ""; } while (cur.moveToNext()); } else { str.append("no result!"); System.out.println("no result!"); } // Toast.makeText(this, this.getString(R.string.toast_querySMS), // Toast.LENGTH_SHORT).show(); return str; }// processResults }