<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小菜毛毛技術(shù)分享

    與大家共同成長

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      164 Posts :: 141 Stories :: 94 Comments :: 0 Trackbacks

    原創(chuàng)  android 2.2 獲取聯(lián)系人,電話,并撥號(hào) 收藏

    該demo是第一次基于android開發(fā)。

    主要功能有: 讀取聯(lián)系人姓名、號(hào)碼,并lisetview 顯示,獲取listview數(shù)據(jù),并發(fā)短信、或者撥號(hào)

    package com.android.hello;

    import android.app.Activity;
    import android.content.Intent;   
    import android.database.Cursor;
    import android.graphics.Color;   
    import android.net.Uri;   
    import android.os.Bundle; 
    import android.telephony.PhoneNumberUtils; 
    import android.util.Log;   
    import android.view.View;   
    import android.widget.AdapterView;   
    import android.widget.LinearLayout;   
    import android.widget.ListAdapter;   
    import android.widget.ListView;
    import android.widget.RelativeLayout;
    import android.widget.TextView;
    import android.widget.Toast; 
    import android.provider.ContactsContract;

    import java.util.ArrayList;   
    import java.util.HashMap;
    import android.widget.SimpleAdapter;

    @SuppressWarnings("deprecation")
    public class hello extends Activity {
        /** Called when the activity is first created. */
       // @SuppressWarnings("deprecation")
    // @Override
     //  
     private static final String TAG="App";   
        ListView listView;   
        ListAdapter adapter;   
        /** Called when the activity is first created. */  
        @Override  
        public void onCreate(Bundle savedInstanceState) {   
            super.onCreate(savedInstanceState);   
           // setContentView(R.layout.main);   
            LinearLayout linearLayout=new LinearLayout(this);   
            linearLayout.setOrientation(LinearLayout.VERTICAL);   
            linearLayout.setBackgroundColor(Color.BLACK);   
            LinearLayout.LayoutParams param=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);   
               
            listView=new ListView(this);   
            listView.setBackgroundColor(Color.BLACK);   
               
            linearLayout.addView(listView,param);   
               
            this.setContentView(linearLayout);   
               
         
          //生成動(dòng)態(tài)數(shù)組,加入數(shù)據(jù)
            ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();        
            ArrayList<HashMap<String, Object>> listItemRead = new ArrayList<HashMap<String, Object>>();     
            Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);      
            while (cursor.moveToNext())    
            {     
             HashMap<String, Object> map = new HashMap<String, Object>();
             String phoneName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
             map.put("ItemTitle", phoneName);//電話姓名
             String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));   
                String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));   
                
                if (hasPhone.compareTo("1") == 0)    
                {   
                    Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);        
                    while (phones.moveToNext())    
                    {      
                     String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));       
                        String phoneTpye = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));       
                       
                        map.put("ItemText", phoneNumber); // 多個(gè)號(hào)碼如何處理
                        
                        Log.d(TAG,"testNum="+ phoneNumber + "type:"+phoneTpye); 
                    }        
                    phones.close();       
                }       
                Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,null, null);   
                while (emails.moveToNext())    
                {                    
                    String emailAddress = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));   
                    String emailType = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));      

                    Log.d(TAG,"testNum="+ emailAddress + "type:"+emailType); 
                }       
                emails.close();
                
                listItem.add(map); 
            }
            
            //生成適配器的Item和動(dòng)態(tài)數(shù)組對(duì)應(yīng)的元素   
            SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//數(shù)據(jù)源    
                android.R.layout.simple_list_item_2,//ListItem的XML實(shí)現(xiàn)   
                //動(dòng)態(tài)數(shù)組與ImageItem對(duì)應(yīng)的子項(xiàng)           
                new String[] {"ItemTitle", "ItemText"},    
                //ImageItem的XML文件里面的一個(gè)ImageView,兩個(gè)TextView ID   
                new int[] {android.R.id.text1,android.R.id.text2}   
            );              
            
            listView.setAdapter(listItemAdapter);   
            cursor.close();  
            
            //listView.setEmptyView(findViewById(R.id.empty));   
               
            listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){   
      
                public void onItemSelected(AdapterView<?> arg0, View arg1,   
                        int arg2, long arg3) {   
                    // TODO Auto-generated method stub   
                    //openToast("滾動(dòng)到:"+arg0.getSelectedItemId());   
                    //短信發(fā)送   
                 setTitle("選擇"+arg2+"項(xiàng)目");
                 openToast("選擇"+arg0.getSelectedItemId()+"項(xiàng)目");
        RelativeLayout lr = (RelativeLayout) arg1;
        TextView mText = (TextView) lr.getChildAt(1);
        openToast(mText.getText().toString());

        String number = mText.getText().toString();
        Log.d(TAG, "number=" + number);
        // 判斷電話號(hào)碼的有效性
        if (PhoneNumberUtils.isGlobalPhoneNumber(number)) {
         Intent intent = new Intent(Intent.ACTION_SENDTO, Uri
           .parse("smsto://" + number));
         intent.putExtra("sms_body", "The SMS text");
         startActivity(intent);             
        } 
                }   
      
                public void onNothingSelected(AdapterView<?> arg0) {   
                    // TODO Auto-generated method stub   
                       
                }   
                   
            });  
            
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){  

       public void onItemClick(AdapterView<?> arg0, View arg1,
         int position, long arg3) {
        // TODO Auto-generated method stub
        // openToast("Click"+Integer.toString(position+1)+"項(xiàng)目");
        RelativeLayout lr = (RelativeLayout) arg1;
        TextView mText = (TextView) lr.getChildAt(1);
        openToast(mText.getText().toString());

        String number = mText.getText().toString();
        Log.d(TAG, "number=" + number);
        // 判斷電話號(hào)碼的有效性
        if (PhoneNumberUtils.isGlobalPhoneNumber(number)) {
         Intent intent = new Intent(Intent.ACTION_DIAL, Uri
           .parse("tel://" + number));
         startActivity(intent);
        }
       }
      });
     }
     
        private void openToast(String str){   
            Toast.makeText(this,str,Toast.LENGTH_SHORT).show();   
        }   

    posted on 2010-12-17 16:58 小菜毛毛 閱讀(1759) 評(píng)論(0)  編輯  收藏 所屬分類: andriod
    主站蜘蛛池模板: 国产V亚洲V天堂无码| 噜噜嘿在线视频免费观看| 久久精品国产精品亚洲人人| 亚洲国产AV一区二区三区四区| 91香蕉成人免费网站| 91精品国产亚洲爽啪在线影院| 久久久久久国产精品免费免费男同 | 亚洲av中文无码字幕色不卡 | 亚洲?V无码成人精品区日韩| 亚洲AV色无码乱码在线观看| 免费高清资源黄网站在线观看| 亚洲精品精华液一区二区| 国产高清免费观看| 自拍偷自拍亚洲精品播放| 午夜私人影院免费体验区| 久久精品国产亚洲精品2020| 亚洲自偷自拍另类图片二区| 久久精品视频免费播放| 亚洲精品无码乱码成人| 免费污视频在线观看| 亚洲女初尝黑人巨高清| 搡女人免费免费视频观看| 久久影视国产亚洲| a级毛片视频免费观看| 国产亚洲综合久久系列| 日本免费在线观看| 91久久亚洲国产成人精品性色| 国偷自产一区二区免费视频| 亚洲国产成人精品不卡青青草原| 午夜网站在线观看免费完整高清观看| 亚洲av不卡一区二区三区 | 日韩免费无码视频一区二区三区| 国产亚洲精品自在久久| 丝瓜app免费下载网址进入ios| 亚洲精品无码午夜福利中文字幕 | 亚欧免费无码aⅴ在线观看| 亚洲大香伊人蕉在人依线| 114一级毛片免费| 亚洲av日韩综合一区久热| 亚洲精品国产精品国自产观看| 好湿好大好紧好爽免费视频|