开发者

showing send_invitations.class cant be resolved to a type in android

开发者 https://www.devze.com 2023-03-08 12:06 出处:网络
hai all..... I amdisplying all my emulatorcontacts into my appliaction.I want to select some of the contacts and putting into an array...I followed the below code...please help me..

hai all..... I am displying all my emulator contacts into my appliaction.I want to select some of the contacts and putting into an array...I followed the below code ...please help me..

package com.android.sample;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class selectedcontacts extends Activity {
    /** Called when the activity is first created. */
    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button existing_contacts = (Button)findViewById(R.id.btn_contact_existing);

        existing_contacts.setOnClickListener(new OnClickListener() {
                        public void onClick(View v){
                            Intent intent_contacts = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
                            /*contacts.setAction(android.content.Intent.ACTION_VIEW);
                            contacts.setData(People.CONTENT_URI);*/
                            startActivityForResult(intent_contacts, 0);
                            //displayContacts();
                        }
                     });
           }
    protected void onActivityResult(int requestCode, int resultCode,Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        String name,mailid,id;
        switch(requestCode)
        {
        case 0:
            {
                if(resultCode == RESULT_OK )
                {
                    Uri contactdata  = data.getData();

                    Cursor cur = managedQuery(contactdata, null, null, null, null);


                    if(cur.moveToFirst())
                    {
                        id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                        Cursor emailCur = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,
                                ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",new String[]{id}, null); 
                        emailCur.moveToFirst();
                        String email = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));


                        name = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                        //mailid = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                        //mailid = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Email._ID));
                       // Toast.makeText(context_contact, "Name:"+name+"\nmailid:"+email, Toast.LENGTH_SHORT).show();
                        Intent intent_add_invitees = new Intent(Contact.this,Send_invitations.class);
                        intent_add_invitees.putExtra("invitee_name", name);
                        intent_add_invitees开发者_开发技巧.putExtra("invitee_mailid", email);
                        setResult(RESULT_OK, intent_add_invitees);
                        finish();

                    }
                }

            }



        }
    }
}

anyone show me the way how to get selected contacts(using checkbox) into an array


See my answer to the post

public static void getContactNumbers(Context context) {
        String contactNumber = null;
        int contactNumberType = Phone.TYPE_MOBILE;
        String nameOfContact = null;
        if (ApplicationConstants.phoneContacts.size() <= 0) {
            ContentResolver cr = context.getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            if (cur.getCount() > 0) {
                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(BaseColumns._ID));
                    nameOfContact = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

                    if (Integer
                            .parseInt(cur.getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                        Cursor phones = cr
                                .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                        null,
                                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                                + " = ?", new String[] { id },
                                        null);

                        while (phones.moveToNext()) {
                            contactNumber = phones.getString(phones
                                    .getColumnIndex(Phone.NUMBER));
                            contactNumberType = phones.getInt(phones
                                    .getColumnIndex(Phone.TYPE));
                            Log.i(TAG, "...Contact Name ...." + nameOfContact
                                    + "...contact Number..." + contactNumber);

                        }
                        phones.close();
                    }

                }
            }// end of contact name cursor
            cur.close();

        }
    }

Thanks Deepak

0

精彩评论

暂无评论...
验证码 换一张
取 消