이것Do! 저것Do!!

"content://sms/inbox/" uri는 각 디바이스마다 다를 수 있다. 당장, 갤럭시S의 경우만 봐도 저런 uri로는 접근이 안되고 있는 실정이다.
따라서, 자신이 테스트하는 환경의 uri가 무엇인지도 잘 알고 있어야 하겠다.

저장된 문자메시지들을 읽어오는 것은 그리 어렵지 않다.
일단, 코드는...
   1: /** Called when the activity is first created. */
   2: @Override
   3: public void onCreate(Bundle savedInstanceState)
   4: {
   5:     super.onCreate(savedInstanceState);
   6:     setContentView(R.layout.main);
   7:  
   8:     Cursor c = getContentResolver().query(Uri.parse("content://sms/inbox/"), 
   9:                                                         null, null, null, null);
  10:     if( c.moveToFirst() ) {
  11:         String msg;
  12:         while( c.moveToNext() ) {
  13:             msg = c.getString(c.getColumnIndex("body"));
  14:             Log.d(LOGTAG, "body:" + msg);
  15:             msg = c.getString(c.getColumnIndex("address"));
  16:             Log.d(LOGTAG, "address:" + msg);
  17:         }
  18:     }
  19:  
  20:     Log.d(LOGTAG, "count:" + c.getCount());
  21:  
  22:     c = getContentResolver().query(Uri.parse("content://sms/sent/"), 
  23:                                                     null, null, null, null);
  24:     if( c.moveToFirst() ) {
  25:         String msg;
  26:         while( c.moveToNext() ) {
  27:             msg = c.getString(c.getColumnIndex("body"));
  28:             Log.d(LOGTAG, "body:" + msg);
  29:             msg = c.getString(c.getColumnIndex("address"));
  30:             Log.d(LOGTAG, "address:" + msg);
  31:         }
  32:     }
  33:  
  34:     Log.d(LOGTAG, "count:" + c.getCount());
  35: }

 

AndroidManifest.xml에 "READ_SMS" permission을 추가해 줘야 한다.

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   3:       package="test.android"
   4:       android:versionCode="1"
   5:       android:versionName="1.0">
   6:  
   7:     <uses-permission android:name="android.permission.READ_SMS"></uses-permission>
   8:     
   9:     <application android:label="@string/app_name" android:icon="@drawable/icon">
  10:         <activity android:name="MySmsTest"
  11:                   android:label="@string/app_name">
  12:             <intent-filter>
  13:                 <action android:name="android.intent.action.MAIN" />
  14:                 <category android:name="android.intent.category.LAUNCHER" />
  15:             </intent-filter>
  16:         </activity>
  17:     </application>
  18: </manifest> 

나의 경우는 현재 HTC의 디자이어 HD를 사용하고 있으므로 HTC Sync를 설치하여 드라이버를 잡아준 뒤 케이블로 연결하여
생성된 apk파일을 인스톨하고서 ddms나 adb logcat으로 확인을 하고 있다.

주의할 점이 하나 있는데, 아직까지 ddms가 한글을 지원하고 있지 않으므로 이를 이용한 디버깅 시, 한글이 깨져서 나오는 문제가 있다.
이런 경우, 한글이 제대로 출력이 되는 쉘을 이용할 수 있다면 adb의 logcat을 통해 한글 메시지 확인이 가능하다.