欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android ContentProvider實(shí)現(xiàn)獲取手機(jī)聯(lián)系人功能

 更新時(shí)間:2017年07月20日 08:56:11   作者:謙之君子  
這篇文章主要為大家詳細(xì)介紹了Android ContentProvider實(shí)現(xiàn)獲取手機(jī)聯(lián)系人功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在之前項(xiàng)目中有用到關(guān)于獲取手機(jī)聯(lián)系人的部分,閑置就想和大家分享一下,話不多說,上代碼:

java部分:

package com.example.content; 
 
import android.content.ContentResolver; 
import android.database.Cursor; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
 
public class MainActivity extends AppCompatActivity { 
 
 private ContentResolver cr; 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 
  //獲取內(nèi)容訪問者 
  cr = getContentResolver(); 
 } 
 public void getContacts(View view){ 
  Uri uri=Uri.parse("content://com.android.contacts/raw_contacts"); 
  Cursor cursor=cr.query(uri,null,null,null,null); 
  while(cursor.moveToNext()){ 
   int _id=cursor.getInt(cursor.getColumnIndex("_id")); 
   String display_name=cursor.getString(cursor.getColumnIndex("display_name")); 
   Log.i("test",_id+" "+display_name); 
   Uri uriData=Uri.parse("content://com.android.contacts/raw_contacts/"+_id+"/data"); 
   Cursor cursorData=cr.query(uriData,null,null,null,null); 
   while(cursorData.moveToNext()){ 
    String mimetype=cursorData.getString(cursorData.getColumnIndex("mimetype")); 
    String data1=cursorData.getString(cursorData.getColumnIndex("data1")); 
    if("vnd.android.cursor.item/phone_v2".equals(mimetype)){ 
     Log.i("test","  "+mimetype+" "+data1); 
    } 
   } 
  } 
 } 
} 

xml部分:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto" 
 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
 android:layout_height="match_parent" tools:context="com.example.content.MainActivity"> 
 
 <Button 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:text="獲取手機(jī)聯(lián)系人" 
  android:onClick="getContacts" 
  /> 
 
</LinearLayout> 

在需要獲取系統(tǒng)的東西的時(shí)候一定不要忘記給權(quán)限啊

AndroidManifest.xml部分:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.content"> 
 
 <!--獲取手機(jī)的聯(lián)系人--> 
 <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> 
 
 <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" 
  android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" 
  android:supportsRtl="true" android:theme="@style/AppTheme"> 
  <activity android:name=".MainActivity"> 
   <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
 
    <category android:name="android.intent.category.LAUNCHER" /> 
   </intent-filter> 
  </activity> 
 </application> 
 
</manifest> 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android使用硬件加速的方式

    Android使用硬件加速的方式

    硬件加速是指利用設(shè)備的硬件資源來加速圖形渲染和圖像處理等操作,以提高應(yīng)用程序的性能和用戶體驗(yàn),Android使用硬件加速的目的是為了提高圖形渲染的性能和效果,本文給大家詳細(xì)介紹了Android如何使用硬件加速,需要的朋友可以參考下
    2023-10-10
  • android使用AsyncTask實(shí)現(xiàn)多線程下載實(shí)例

    android使用AsyncTask實(shí)現(xiàn)多線程下載實(shí)例

    這篇文章主要介紹了android使用AsyncTask實(shí)現(xiàn)多線程下載實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • Android編程實(shí)現(xiàn)修改標(biāo)題欄位置使其居中的方法

    Android編程實(shí)現(xiàn)修改標(biāo)題欄位置使其居中的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)修改標(biāo)題欄位置使其居中的方法,涉及Android布局設(shè)置的簡(jiǎn)單實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • 詳解Android中AsyncTask機(jī)制

    詳解Android中AsyncTask機(jī)制

    在Android當(dāng)中,提供了兩種方式來解決線程直接的通信問題,一種是通過Handler的機(jī)制,還有一種就是今天要詳細(xì)講解的 AsyncTask 機(jī)制,對(duì)android中asynctask相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • Android實(shí)戰(zhàn)打飛機(jī)游戲之無限循環(huán)的背景圖(2)

    Android實(shí)戰(zhàn)打飛機(jī)游戲之無限循環(huán)的背景圖(2)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)戰(zhàn)打飛機(jī)游戲之無限循環(huán)的背景圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • RxJava 1升級(jí)到RxJava 2過程中踩過的一些“坑”

    RxJava 1升級(jí)到RxJava 2過程中踩過的一些“坑”

    RxJava2相比RxJava1,它的改動(dòng)還是很大的,那么下面這篇文章主要給大家總結(jié)了在RxJava 1升級(jí)到RxJava 2過程中踩過的一些“坑”,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下來要一起看看吧。
    2017-05-05
  • Flutter混合開發(fā)詳解

    Flutter混合開發(fā)詳解

    這篇文章主要介紹了Flutter混合開發(fā)詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Android手機(jī)拍照或選取圖庫圖片作為頭像

    Android手機(jī)拍照或選取圖庫圖片作為頭像

    這篇文章主要介紹了Android手機(jī)拍照或選取圖庫圖片作為頭像的相關(guān)資料,需要的朋友可以參考下
    2015-06-06
  • Android Studio中生成aar文件及本地方式使用aar文件的方法

    Android Studio中生成aar文件及本地方式使用aar文件的方法

    這篇文章給大家講解Android Studio中生成aar文件以及本地方式使用aar文件的方法,也就是說 *.jar 與 *.aar 的生成與*.aar導(dǎo)入項(xiàng)目方法,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2017-12-12
  • 利用Android兩行代碼真正殺死你的App

    利用Android兩行代碼真正殺死你的App

    這篇文章主要介紹了利用Android兩行代碼真正殺死你的App,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03

最新評(píng)論