2017-02-17 104 views

回答

0

這是因爲您使用的Android操作系統版本比棒棒糖大。

所以你要添加的權限爲您的聯繫人

公共無效askForContactPermission(){ 如果(Build.VERSION.SDK_INT> = Build.VERSION_CODES.M){ 如果(ContextCompat.checkSelfPermission(getActivity() ,Manifest.permission.READ_CONTACTS)= PackageManager.PERMISSION_GRANTED){

 // Should we show an explanation? 
     if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), 
       Manifest.permission.READ_CONTACTS)) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
      builder.setTitle("Contacts access needed"); 
      builder.setPositiveButton(android.R.string.ok, null); 
      builder.setMessage("please confirm Contacts access");//TODO put real question 
      builder.setOnDismissListener(new DialogInterface.OnDismissListener() { 
       @TargetApi(Build.VERSION_CODES.M) 
       @Override 
       public void onDismiss(DialogInterface dialog) { 
        requestPermissions(
          new String[] 
            {Manifest.permission.READ_CONTACTS} 
          , PERMISSION_REQUEST_CONTACT); 
       } 
      }); 
      builder.show(); 
      // 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. 

     } 
+0

沒有。 android 5.0.2版本是。 –

相關問題