2016-09-06 39 views
-1

我想要構建一個應用程序,在應用程序激活時通過幫助將消息發送給選定的聯繫人。我點擊了激活切換時創建了一個選擇聯繫人但無法添加消息功能的應用程序關鍵發送消息給Android中的選定聯繫人

textView1 = (TextView) findViewById(R.id.contact_number1); 
textView2 = (TextView) findViewById(R.id.contact_number2); 

public void pickAContactNumber(View view) 
{ 
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); 
startActivityForResult(intent, PICK_CONTACT1); 
} 
+0

textView1 =(TextView的)findViewById(R。 id.contact_number1); textView2 =(TextView)findViewById(R.id.contact_number2); ------------------------------------------------ ----------- public void pickAContactNumber(View view){ Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); startActivityForResult(intent,PICK_CONTACT1); } –

+0

你是什麼意思的「消息」?發送選定的聯繫人短信? – marmor

回答

0

當你有得到接觸呼叫活動,你會得到onActivityResult方法接觸,並從那裏你可以實現如下的邏輯,

@Override 
    public void onActivityResult(int reqCode, int resultCode, Intent data) { 
    super.onActivityResult(reqCode, resultCode, data); 

    switch (reqCode) { 
     case (PICK_CONTACT1) : 
      if (resultCode == Activity.RESULT_OK) { 

       Uri contactData = data.getData(); 
       Cursor c = managedQuery(contactData, null, null, null, null); 
       if (c.moveToFirst()) { 

        String id =c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID)); 
        String hasPhone =c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 

        if (hasPhone.equalsIgnoreCase("1")) { 
         Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id, 
        null, null); 
          phones.moveToFirst(); 
          cNumber = phones.getString(phones.getColumnIndex("data1")); 
          System.out.println("number is:"+cNumber); 
        sendMessage(cNumber); 

        } 
        //String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
       } 
      } 
      break; 
     } 
    } 

    public void sendMessage(String number) 
    { 
    } 
+0

okk感謝您的幫助:) –

相關問題