permission.READ_CONTACTS does not seem to work

前端 未结 6 2069
一向
一向 2021-02-18 17:10

I\'m working on a simple app that browses through the user\'s contacts. Unfortunately I keep getting the following error:

java.lang.SecurityException: Permission         


        
6条回答
  •  长发绾君心
    2021-02-18 17:40

    None of the above helped. The solution is quite simple. you'll need a runtime permission request.

    with or without placing the permission in your manifest, You will need to request that permission from the User on-the-fly.

    if( getApplicationContext().checkSelfPermission( Manifest.permission.READ_CONTACTS ) != PackageManager.PERMISSION_GRANTED )
         ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_CONTACTS}, resultValue);
    

    only then after the approval you will be able to query the contacts phone number/name etc.

提交回复
热议问题