2016-07-28 46 views

回答

0

您应该检查用户是否已授予TelephonyManager 6.0版权限。您可以查看详细信息link

下面的代码检查,如果有必要的应用程序有权读取用户的联系人,并请求权限:

// Here, thisActivity is the current activity 
if (ContextCompat.checkSelfPermission(thisActivity, 
      Manifest.permission.READ_CONTACTS) 
    != PackageManager.PERMISSION_GRANTED) { 

// Should we show an explanation? 
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, 
     Manifest.permission.READ_CONTACTS)) { 

    // Show an expanation to the user *asynchronously* -- don't block 
    // this thread waiting for the user's response! After the user 
    // sees the explanation, try again to request the permission. 

} else { 

    // No explanation needed, we can request the permission. 

    ActivityCompat.requestPermissions(thisActivity, 
      new String[]{Manifest.permission.READ_CONTACTS}, 
      MY_PERMISSIONS_REQUEST_READ_CONTACTS); 

    // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an 
    // app-defined int constant. The callback method gets the 
    // result of the request. 
} 

}

+0

@usha:没有ü检查 – DKV

+0

如果用户给予了许可,那么我们如何访问他的联系人 – Usha

+0

@Ushay与下面的版本相同。在访问联系人之前,您只需要获得用户的许可即可。 – DKV

相关问题