-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();
}
}
});
有棉花糖或更高操作系統版本的設備 –
此代碼用於檢查棉花糖或更高操作系統的權限。如果權限授予READ_PHONE_STATE,則loginAction();將打電話,否則彈出打開授予許可READ_PHONE_STATE –
檢查此http://www.truiton.com/2016/04/obtaining-runtime-permissions-android-marshmallow-6-0/ –