title: How to fix StrictMode policy violation in android while fetching all mobile number?
body: <p>I am fetching all mobile numbers using cursor query. I have enabled strict mode getting this exception.</p>
  
  <p>Here is my code for fetching mobile number :</p>
  
  <pre><code>public String queryForPhoneNumber(String contactId) {
      final String[] projection = new String[] {
              Phone.NUMBER,
              Phone.TYPE,
      };
  
      final Cursor phone = getActivity().getContentResolver().query(
              Phone.CONTENT_URI,  
              projection,
              Data.DISPLAY_NAME + "=?",
              new String[]{contactId},
              null);
  
      if(phone.moveToFirst()) {
          final int contactNumberColumnIndex = phone.getColumnIndex(Phone.NUMBER);
          //final int contactTypeColumnIndex = phone.getColumnIndex(Phone.TYPE);
  
          while(!phone.isAfterLast()) {
              mFmFmUserMobile = phone.getString(contactNumberColumnIndex);
              //final int type = phone.getInt(contactTypeColumnIndex);
              phone.moveToNext();
          }
  
      }
      phone.close();
  
      if(mFmFmUserMobile.contains(" ")){
          mFmFmUserMobile.replace(" ", "");
      }
      //mFmFmUserMobile.substring(mFmFmUserMobile.length()-10,mFmFmUserMobile.length()
  
      return mFmFmUserMobile;
  }
  </code></pre>
  
  <p>Exception :</p>
  
  <pre><code>04-25 09:51:15.035: D/StrictMode(27661): StrictMode policy violation; ~duration=31 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=2335 violation=2
  04-25 09:51:15.035: D/StrictMode(27661):    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1135)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1041)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:842)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.CursorToBulkCursorAdaptor.getBulkCursorDescriptor(CursorToBulkCursorAdaptor.java:148)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:118)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.os.Binder.execTransact(Binder.java:404)
  04-25 09:51:15.035: D/StrictMode(27661):    at dalvik.system.NativeStart.run(Native Method)
  04-25 09:51:15.035: D/StrictMode(27661): # via Binder call with stack:
  04-25 09:51:15.035: D/StrictMode(27661): android.os.StrictMode$LogStackTrace
  04-25 09:51:15.035: D/StrictMode(27661):    at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1705)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.os.Parcel.readExceptionCode(Parcel.java:1447)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:134)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.content.ContentResolver.query(ContentResolver.java:461)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.content.ContentResolver.query(ContentResolver.java:404)
  04-25 09:51:15.035: D/StrictMode(27661):    at com.newtglobal.fmfm.InviteFriendFragement.queryForPhoneNumber(InviteFriendFragement.java:954)
  04-25 09:51:15.035: D/StrictMode(27661):    at com.newtglobal.fmfm.InviteFriendFragement$ContactsAdapter.bindView(InviteFriendFragement.java:747)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.AbsListView.obtainView(AbsListView.java:2255)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.ListView.makeAndAddView(ListView.java:1790)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.ListView.fillDown(ListView.java:691)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.ListView.fillGap(ListView.java:655)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5143)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3243)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.AbsListView.onTouchMove(AbsListView.java:3587)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.widget.AbsListView.onTouchEvent(AbsListView.java:3431)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.View.dispatchTouchEvent(View.java:7736)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2212)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2218)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  04-25 09:51:15.035: D/StrictMode(27661):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
  04-25 09:51:15.035: D/StrictMode(27661):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
  04-25 09:51:15.035: D/StrictMode(27661):    at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
  04-25 09:51:15.035: D/StrictMode(27661):    at c
  </code></pre>
  
  <p>Any help would be helpful for me. Thanks in advance.</p>