Thursday, August 30, 2012

Get Contact List and Send them Message at once (Group Message view intent)


Cursor cursor;
      
        private void populateContactList() {
               // Build adapter with contact entries
                                          
              cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                         new String[] { BaseColumns._ID, Phone.DISPLAY_NAME,Phone.NUMBER }, null, null, null);
              startManagingCursor(cursor);


              String[] from = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER };

              int[] to = new int[] { R.id.tv_name, R.id.tv_contact };

              SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                           R.layout.phone_listview, cursor, from, to);
              lv_phonecontacts.setAdapter(adapter);
             
       }
      
        public void inviteToPhoneContacts()
        {           
               String ur="";
               SparseBooleanArray checked = lv_phonecontacts.getCheckedItemPositions();
               for (int i = 0; i < checked.size(); i++) {
                   if(checked.get(i))
                   {
                      cursor.moveToPosition(checked.indexOfKey(i));                 
                      ur+=cursor.getString(1)+"<"+cursor.getString(2)+">;";
                   }
                      
               }
               
               Log.i("ur","smsto:"+ur);
               Uri uri = Uri.parse("smsto:"+ur);  
               Intent it = new Intent(Intent.ACTION_SENDTO, uri);  
               it.putExtra("sms_body", "Please Install NTAD.This is Demo Text.");  
               startActivity(it);       
               
        }

No comments:

Post a Comment