android:textSize="18sp" app:layout_constraintBottom_toTopOf="@id/contactList" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> Kontaktlar ro'yxatini ko'rsatish uchun ListView elementidan foydalanamiz. Va MainActivity sinfida biz kontaktlarni olamiz: - package com.example.contactsapp;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.app.ActivityCompat;
- import androidx.core.content.ContextCompat;
- import android.Manifest;
- import android.content.ContentResolver;
- import android.content.pm.PackageManager;
- import android.database.Cursor;
- import android.os.Bundle;
import android.provider.ContactsContract; - import android.provider.ContactsContract;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import android.widget.Toast;
- import java.util.ArrayList;
- public class MainActivity extends AppCompatActivity {
- private static final int REQUEST_CODE_READ_CONTACTS=1;
- private static boolean READ_CONTACTS_GRANTED =false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // ruxsat olamiz
- int hasReadContactPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
Do'stlaringiz bilan baham: |