2011-03-30 15 views
0

我有ListView的收件箱SMS.I我試圖,如果我點擊ListView中的任何項目,它會打開短信管理器與收件目的地號碼從收到短信,但我不知道我怎麼能做到這一點。有人能幫助我嗎?對不起我的英語。Android:OnItemClickListener

list1.setOnItemClickListener(new OnItemClickListener() { 

    @Override 
      public void onItemClick(AdapterView<?> arg, View view, int position,long id) { 

       SmsManager m = SmsManager.getDefault(); 
       Uri uriSMSURIs = Uri.parse("content://sms/inbox"); 

       int poss = list1.getSelectedItemPosition(); 
       String pos = String.valueOf(poss); 
       Log.d(TAG, "pos: " + pos); 

       Cursor cc = getContentResolver().query(uriSMSURIs, null, pos, null, null); 

        String phoneNumber = cc.getString(cc.getColumnIndex("address")); 
       m.sendTextMessage(phoneNumber , null, null , null, null); 

回答

1

可以調用默認的短信應用,意圖:

Intent sendIntent = new Intent(Intent.ACTION_VIEW); 
    sendIntent.putExtra("address", "123456789"); 
    sendIntent.putExtra("sms_body", "Content of the SMS goes here..."); 
    sendIntent.setType("vnd.android-dir/mms-sms"); 
    startActivity(sendIntent); 
+0

是的,但我想,如果我在ListView中的任何項目上單擊(所有短信列表)它將會被自動從填寫電話號碼短信女巫我點擊ListView。 – Husky 2011-03-30 19:09:26

+0

在這裏和我一起工作。我沒有爲你寫代碼。我給你一個如何用額外的數據部分來啓動意圖的例子。我還沒有嘗試過你想要做的事情,但我會假設你可以用你從查詢中提取的phoneNumber代替我的例子中的「123456789」。 – 2011-03-30 19:28:30

+0

我已經這樣做,但它仍然dosn't工作:( – Husky 2011-03-30 19:33:23