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

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

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

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

    與大家共同成長(zhǎng)

      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 小菜毛毛 閱讀(1758) 評(píng)論(0)  編輯  收藏 所屬分類: andriod
    主站蜘蛛池模板: 人妻视频一区二区三区免费| 中文字幕亚洲精品| 国产v精品成人免费视频400条| 男女啪啪免费体验区| 亚洲综合偷自成人网第页色| 亚洲国产婷婷六月丁香| 免费一级毛片在线播放| AV无码免费永久在线观看| 少妇性饥渴无码A区免费 | 亚洲欧美精品午睡沙发| 亚洲国产精品不卡在线电影| 国产91精品一区二区麻豆亚洲 | 亚洲国产精品xo在线观看| 亚洲香蕉网久久综合影视| 免费国产成人午夜电影| 成人看的午夜免费毛片| 亚洲高清中文字幕免费| 久久国产高潮流白浆免费观看| 插鸡网站在线播放免费观看| 免费在线观看一区| 在线观看亚洲视频| 亚洲精品国产suv一区88| 亚洲日本久久久午夜精品| 亚洲另类图片另类电影| 久久亚洲AV成人无码电影| 亚洲av丰满熟妇在线播放| 国产精品国产亚洲精品看不卡| 亚洲伊人久久综合影院| 亚洲美女在线国产| 亚洲视频在线精品| 亚洲综合激情另类专区| 久久亚洲中文字幕精品一区四| 亚洲日本一区二区三区在线不卡| 国产特级淫片免费看| 国产成人免费高清在线观看| 韩国欧洲一级毛片免费| 日本免费网站在线观看| 国产无遮挡吃胸膜奶免费看视频| 尤物永久免费AV无码网站| 免费a级黄色毛片| 亚洲精品国产成人影院|