2017-03-22 62 views
-5

submitButtonLayout =(LinearLayout)findViewById(R.id.submit_button_layout);爲什麼我們使用這段代碼請任何一個告訴我

submitButtonLayout.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      int permissionCheck = ContextCompat.checkSelfPermission(context, android.Manifest.permission.READ_PHONE_STATE); 

      if (permissionCheck != PackageManager.PERMISSION_GRANTED) { 
       ActivityCompat.requestPermissions((Activity) context, new String[]{ android.Manifest.permission.READ_PHONE_STATE}, Utils.REQUEST_READ_PHONE_STATE); 
      } else { 
       loginAction(); 
      } 
     } 
    }); 
+0

有棉花糖或更高操作系統版本的設備 –

+0

此代碼用於檢查棉花糖或更高操作系統的權限。如果權限授予READ_PHONE_STATE,則loginAction();將打電話,否則彈出打開授予許可READ_PHONE_STATE –

+0

檢查此http://www.truiton.com/2016/04/obtaining-runtime-permissions-android-marshmallow-6-0/ –

回答

0

https://developer.android.com/training/permissions/requesting.html

 
Beginning in Android 6.0 (API level 23), 
users grant permissions to apps while the app is running, 
not when they install the app. 
This approach streamlines the app install process, 
since the user does not need to grant permissions when they install or update the app. 
It also gives the user more control over the app's functionality; 
for example, a user could choose to give a camera app access to the camera but not to the device location. 
The user can revoke the permissions at any time, by going to the app's Settings screen. 

的你所需要的基本概況。通過鏈接獲取有關實施和其他限制的更多細節。

+0

謝謝你們兄弟..mohammed-atif –

相關問題