国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

androd—Intent操作ContentProvider獲取電話號碼

2019-11-09 15:23:08
字體:
供稿:網(wǎng)友
import android.app.Activity;import android.content.ContentUris;import android.content.Intent;import android.database.Cursor;import android.net.Uri;import android.os.Bundle;import android.PRovider.ContactsContract;import android.widget.Toast; public class MyIntentContentDemo extends Activity {    private static final int PICK_CONTACT_SUBACTIVITY = 1;              // 定義操作標(biāo)記    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        super.setContentView(R.layout.main);        Uri uri = Uri.parse("content://contacts/people");               // 連接URI        Intent intent = new Intent(Intent.ACTION_PICK, uri);            // 指定Intent        super.startActivityForResult(intent, PICK_CONTACT_SUBACTIVITY);// 調(diào)用Intent    }    @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        switch (requestCode) {        case PICK_CONTACT_SUBACTIVITY:                                  // 接收返回的數(shù)據(jù)            Uri ret = data.getData();                                   // 單個數(shù)據(jù)Uri            String phoneSelection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID                        + "=?";                                         // 設(shè)置查詢條件            String[] phoneSelectionArgs = { String.valueOf(ContentUris                    .parseId(ret)) };                                   // 查詢參數(shù)            Cursor c = super.managedQuery(                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,                    phoneSelection, phoneSelectionArgs, null);          // 查詢?nèi)渴謾C號碼            StringBuffer buf = new StringBuffer() ;                 // 用于接收全部電話            buf.append("電話號碼是:") ;            for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {   // 循環(huán)取數(shù)據(jù)                buf.append(c.getString(c.getColumnIndex(                        ContactsContract.CommonDataKinds.Phone.NUMBER)))                            .append("、");                               // 取出電話號碼            }            Toast.makeText(this, buf, Toast.LENGTH_LONG).show();        // 顯示信息        }    }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 哈尔滨市| 特克斯县| 讷河市| 大冶市| 宣汉县| 白山市| 塔城市| 新巴尔虎左旗| 德惠市| 兖州市| 黄冈市| 襄樊市| 天台县| 江阴市| 青田县| 宣武区| 仪陇县| 郑州市| 平塘县| 沾益县| 临朐县| 光山县| 玉树县| 伽师县| 甘南县| 伊金霍洛旗| 太谷县| 东乌珠穆沁旗| 龙山县| 清流县| 盱眙县| 嘉祥县| 齐齐哈尔市| 彰武县| 石林| 丽江市| 会理县| 临西县| 汽车| 德安县| 丰县|