Issue With Challenge 2

This error doesn’t force my app to crash. Instead, it does nothing but post 1 of the 2 errors above on my Android Monitor:

  • D/ViewRootImpl: ViewPostImeInputStage processPointer 0
  • D/ViewRootImpl: ViewPostImeInputStage processPointer 1

Here is part of the code because I’m not sure how to just copy an paste all of my code without the format getting all wonky. I’ll put it all up if necessary though. I feel like it’s a really silly permission issue that I’m unaware of…I’m a new dev.

Suspect OnClick Code:

     int permissionCheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CONTACTS);
     if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
          requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_PERMISSION);
     } else {
          startActivityForResult(pickContact, REQUEST_CONTACT);
     }

});

Call Button OnClick Code:

Uri phoneURI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER};
String selection = ContactsContract.CommonDataKinds.Phone._ID + "= ?";
String[] selectionArgs = {Long.toString(mCrime.getPhoneId())};

Cursor c = getActivity().getContentResolver().query(phoneURI, projection, selection, selectionArgs, null);

try {

     if (c.getCount() == 0) {
              return;
         }

         c.moveToFirst();
         String phoneNumber = c.getString(0);
         Uri call = Uri.parse("tel:" + phoneNumber);
         Intent callNumber = new Intent(Intent.ACTION_DIAL, call);
         startActivity(callNumber);

    } finally {
         c.close();
    }

OnActivityResult:

There isn't much that changed in here other than me modifying the queryFields variable to accomodate for the _ID of my contact and updating that value inside of a method that I called setPhoneId(id) which is a part of my model.

onRequestPermissionsResult:

if (requestCode == REQUEST_PERMISSION) {
     if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
          Intent pickContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
          startActivityForResult(pickContact, REQUEST_CONTACT);
     }
}

Those two log statements look like standard log spew to me. I do not think that is an issue or relevant to the problem that you are seeing.

So, what happens when this code runs? Nothing from the user’s perspective?

I recommend attachinhttps://forums.bignerdranch.com/t/issue-with-challenge-2/11878g the debugger and stepping through your code to see where things are not working correctly. Let me know how that goes and we can continue to troubleshoot.