2012-07-09 7 views
0

2.1 플랫폼을 사용하고 있습니다. 에뮬레이터에서 모든 SMS를 검색하는 중입니다. 아니요 컴파일 오류, 아니요 Logcat 오류 내 코드에 포함되어 있습니다 .ModifyMSMS에 대한 권한을 매니페스트 파일에 포함 시켰습니다. 코드를 실행해도 ListView에 표시되지 않습니다. 내 XML 파일에는 하나의 ListView 만 있습니다. 해당 ListView에서 에뮬레이터에서 모든 SMS 형식 (번호 : Sms 본문)을 표시하려고합니다.Sms 검색 중 작동하지 않습니까?

코드

public class SMSActivity extends Activity { 
/** Called when the activity is first created. */ 
    ListView lview; 
    String Body = "" ; 
    int Number; 
    ArrayList<String> smslist=new ArrayList<String>(); 
    ArrayAdapter<String> itemAdapter; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    lview =(ListView)findViewById(R.id.lv); 
    itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,smslist); 
    lview.setAdapter(itemAdapter); 

    ContentResolver cr = getContentResolver(); 
    Cursor c = cr.query(Uri.parse("content://sms/"), new String[] { "_id", "address", "date", "body","read" },"_id = "+null, null, null); 

    while(c.moveToNext()){ 

    Number = c.getInt(c.getColumnIndexOrThrow("address")); 

    Body = c.getString(c.getColumnIndexOrThrow("body")).toString(); 

    smslist.add(Number + "\n" + Body); 
    } 
    itemAdapter.notifyDataSetChanged(); 
    c.close(); 
} 
} 

어떻게이 문제를 해결하기 위해?

+0

를 사용하여 열 이름을 조회 할 수 있습니다

Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null); 

.. : http://android10.org/index.php/articlesfullapplications/241-sms-messaging-in-android-send - 및 - 수신 및 http://stackoverflow.com/a/11356430/1168654 그것은 당신을 도울 수 있습니다. –

+0

이 사이트는 에뮬레이터간에 SMS를 보내고 가져 오는 중입니다 ..... 내 코드를 확인하십시오 ... – Hari

+0

안녕하세요, 지난 두 번째 링크에 대해 잊어 버렸습니다. http://stackoverflow.com/a/11356430/1168654 –

답변

1

당신이하고있는 오류는 당신이 SMS를 읽고 싶은 것을 언급하지만 당신은 당신이 SMS를 읽을해야하는 경우, 등등

보낼 편지함은받은 편지함에서 them.eg 필요에서 폴더 말을 잊었다 받은 편지함에서 다음을 사용합니다. 이 참조 또한

for (int i = 0; i < cursor.getColumnCount(); i++) { 

    Log.i("info", cursor.getColumnName(i)); 
} 
+0

고마워요 Vipul ... 제대로 작동하는 커서 만 변경했습니다. 아래 for 루프에 대해 알아야합니다. 우리가 실제로 사용하는 목적은 무엇입니까? – Hari

관련 문제