title: How can I make my app read my contact list?
body: <p>My <code>MainActivity</code> has a <code>getContactList()</code> method that does what it's suppose to. I also have recyclerViews and adapters and all that work when viewing <code>activity_main.xml</code> in an emulator, so the problem isn't there. The problem I'm having is making the app read the arrayList of contacts or just doing it automatically.</p>
  <p>Here's my MainActivity code (what's more important is the <code>onCreate</code> method which loads everything it's suppose to and the <code>getContactList()</code>):</p>
  <pre><code>package com.app.wolfix;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.constraintlayout.widget.ConstraintLayout;
  import androidx.core.app.ActivityCompat;
  import androidx.core.content.ContextCompat;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.Manifest;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.database.Cursor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.ContactsContract;
  import android.widget.Button;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity {
      RecyclerView recyclerView;
      ArrayList&lt;ContactModel&gt; arrayList = new ArrayList&lt;ContactModel&gt;();
      MainAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          recyclerView = findViewById(R.id.recycler_view);
  
          adapter = new MainAdapter(this, arrayList);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          recyclerView.setAdapter(adapter);
  
          Button add_btn = findViewById(R.id.add_btn);
  
          add_btn.setOnClickListener(v -&gt; startActivity(new Intent(MainActivity.this, Add_Contact.class)));
  
          Button rem_btn = findViewById(R.id.rem_btn);
  
          rem_btn.setOnClickListener(v -&gt; startActivity(new Intent(MainActivity.this, Main_Remove_Contact.class)));
  
          checkPermission();
      }
  
      private void checkPermission() {
          if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED){
              ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_CONTACTS}, 100);
          }else{
              getContactList();
          }
      }
  
      private void getContactList() {
          Uri uri = ContactsContract.Contacts.CONTENT_URI;
  
          String sort = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME+&quot; ASC&quot;;
  
          Cursor cursor = getContentResolver().query(
                  uri, null, null, null, sort);
  
          if (cursor.getCount() &gt; 0){
              while (cursor.moveToNext()){
                  String id = cursor.getString(cursor.getColumnIndexOrThrow(
                          ContactsContract.Contacts._ID
                  ));
              }
          }
      }
  }
  </code></pre>
  <p><code>checkPermission()</code> is just a verification check that goes for <code>getContactList()</code> once it accepts it, <strong>BUT</strong> there could be an error there too that I just can't really dissect (it's code from a video tutorial I saw but I have been getting some help and there have been some code changes).</p>
  <p>Would it be easier to just make a <code>while()</code> loop somewhere to read all the contacts and add them to <code>arrayList</code> or is there an already added feature that does that already, since I already had that working before. Here's a tutorial I saw a long time ago that used to work on my app too: <a href="https://www.youtube.com/watch?v=esDWSfBa-oc" rel="nofollow noreferrer">https://www.youtube.com/watch?v=esDWSfBa-oc</a></p>
  <p>Thanks in advance!</p>