2016-07-06 39 views
0

我在我的應用程序中實現了運行時權限,但我無法做到顯示CALL_PHONE權限。我需要顯示兩個權限,read_contact和call_phone。我可以完美顯示read_contact,但不能獲得call_phone權限。我無法在運行時權限中顯示Manifest.permission.CALL_PHONE

我正在使用AVD仿真器進行測試。

一些幫助將是apreciate!

這是我的代碼:

 callPesmission.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       requestCallPhonePermission(); 
      } 
     }); 

     contactPesmission.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       requestContactsPermission(); 
      } 
     }); 


private void requestContactsPermission() { 
     String locationPermission = Manifest.permission.READ_CONTACTS; 
     int hasPermission = ContextCompat.checkSelfPermission(getActivity(), locationPermission); 
     String[] permissions = new String[] { locationPermission }; 
     if (hasPermission != PackageManager.PERMISSION_GRANTED) { 
      requestPermissions(permissions, REQUEST_CONTACTS); 
     } else { 
      Toast.makeText(getActivity(), "We already have persmission", Toast.LENGTH_SHORT).show(); 
     } 
    } 

    private void requestCallPhonePermission() { 
     String callPermission = Manifest.permission.CALL_PHONE; 
     int hasPermission = ContextCompat.checkSelfPermission(getActivity(), callPermission); 
     String[] permissions = new String[] { callPermission }; 
     if (hasPermission != PackageManager.PERMISSION_GRANTED) { 
      requestPermissions(permissions, REQUEST_CALL_PHONE); 
     } else { 
      Toast.makeText(getActivity(), "We already have persmission", Toast.LENGTH_SHORT).show(); 
     } 
    } 

@Override 
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 
     switch (requestCode) { 
      case REQUEST_CONTACTS: 
       if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        Toast.makeText(getActivity(), "READ_CONTACTS GRANTED", Toast.LENGTH_SHORT).show(); 
       } else { 
        Toast.makeText(getActivity(), "READ_CONTACTS DENIED", Toast.LENGTH_SHORT).show(); 
       } 
       break; 
      case REQUEST_CALL_PHONE: 
       if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        Toast.makeText(getActivity(), "CALL_PHONE GRANTED", Toast.LENGTH_SHORT).show(); 
       } else { 
        Toast.makeText(getActivity(), "CALL_PHONE DENIED", Toast.LENGTH_SHORT).show(); 
       } 
       break; 
      default: 
       super.onRequestPermissionsResult(requestCode, permissions, grantResults); 
     } 
    } 

回答

2

我什麼也看不到你的代碼錯誤在那裏,

確認它是否實際存在於manifest.xml中。

對話框不會,如果它不存在,顯示明顯的,如果我們嘗試使用功能反正

+0

看到你自己的答案:)發生在我們最好的可能拋出安全異常:)運行權限可以是疼痛 – Kushan

+0

是的,絕對同意 –

1

我忘了添加的權限在清單.....

<uses-permission android:name="android.permission.CALL_PHONE" />