最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

在之前項(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)的東西的時候一定不要忘記給權(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> 

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

相關(guān)文章

  • Android自定義WaveProgressView實(shí)現(xiàn)水波紋加載需求

    Android自定義WaveProgressView實(shí)現(xiàn)水波紋加載需求

    這篇文章主要為大家詳細(xì)介紹了Android自定義WaveProgressView實(shí)現(xiàn)水波紋加載需求,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • Android錄音播放管理工具

    Android錄音播放管理工具

    這篇文章主要為大家詳細(xì)介紹了Android錄音播放管理工具,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • 詳解Android 視頻滾動列表(偷懶型)

    詳解Android 視頻滾動列表(偷懶型)

    小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧本篇文章主要介紹了Android 視頻滾動列表(偷懶型),
    2017-11-11
  • Android webveiw 出現(xiàn)棧錯誤解決辦法

    Android webveiw 出現(xiàn)棧錯誤解決辦法

    這篇文章主要介紹了Android webveiw 出現(xiàn)棧錯誤解決辦法的相關(guān)資料,出現(xiàn)java.lang.UnsupportedOperationException: For security reasons, WebView is not allowed in privileged processes,這里提供解決辦法,需要的朋友可以參考下
    2017-08-08
  • Android手勢左右滑動效果

    Android手勢左右滑動效果

    這篇文章主要為大家詳細(xì)介紹了Android手勢左右滑動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Kotlin中空判斷處理操作實(shí)例

    Kotlin中空判斷處理操作實(shí)例

    最近使用kotlin重構(gòu)項(xiàng)目,遇到了一個小問題,在Java中,可能會遇到判斷某個對象是否為空,為空執(zhí)行一段邏輯,不為空執(zhí)行另外一段邏輯,下面這篇文章主要給大家介紹了關(guān)于Kotlin中空判斷處理操作的相關(guān)資料,需要的朋友可以參考下
    2022-07-07
  • Android串口開發(fā)之使用JNI實(shí)現(xiàn)ANDROID和串口通信詳解

    Android串口開發(fā)之使用JNI實(shí)現(xiàn)ANDROID和串口通信詳解

    這篇文章主要給大家介紹了關(guān)于Android串口開發(fā)之使用JNI實(shí)現(xiàn)ANDROID和串口通信的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • Android整理好的圖片壓縮工具類

    Android整理好的圖片壓縮工具類

    今天小編就為大家分享一篇關(guān)于Android整理好的圖片壓縮工具類,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • 詳解Glide4.0集成及使用注意事項(xiàng)

    詳解Glide4.0集成及使用注意事項(xiàng)

    這篇文章主要介紹了詳解Glide4.0集成及使用注意事項(xiàng),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • Android自定義實(shí)現(xiàn)一個省份簡稱鍵盤

    Android自定義實(shí)現(xiàn)一個省份簡稱鍵盤

    這篇文章主要為大家詳細(xì)介紹了Android如何自定義實(shí)現(xiàn)一個省份簡稱鍵盤,可以用在車牌輸入等地方,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-06-06

最新評論

铜梁县| 临湘市| 静海县| 舒城县| 巩义市| 清原| 长武县| 建宁县| 康保县| 郓城县| 合江县| 温泉县| 修水县| 日土县| 安达市| 信丰县| 黄石市| 大方县| 宣汉县| 石嘴山市| 云和县| 贡嘎县| 祥云县| 永仁县| 安塞县| 广元市| 连平县| 阳山县| 江都市| 外汇| 西盟| 昌平区| 望都县| 墨脱县| 太和县| 吴桥县| 荣昌县| 谷城县| 旌德县| 金阳县| 页游|