2016-07-28 44 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

相關問題