wrote a pure demo to try EasyPermissions, and the code was posted. In this sentence of EasyPermissions.hasPermissions (this, perms) applying for permission, the return will always be true. It is puzzling, and there is a lot of advice from various gods
.public class TestActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{
public final static String TAG = TestActivity.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
TextView t = findViewById(R.id.textView_top_title);
t.setText("");
findViewById(R.id.button_login).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestPermissions();
}
});
}
private static final int RC_CAMERA_AND_RECORD_AUDIO = 10000;
/**
*
*/
private void requestPermissions() {
String[] perms = {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION};
//
if (EasyPermissions.hasPermissions(this, perms)) {
// ,
openCamera();
} else {
// ,
// this:
// Dialog
// RC_CAMERA_AND_RECORD_AUDIO ,
// perms
EasyPermissions.requestPermissions(this, ", ", RC_CAMERA_AND_RECORD_AUDIO, perms);
}
}
private void openCamera(){
Toast.makeText(this, "", Toast.LENGTH_SHORT)
.show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
// Do something after user returned from app settings screen, like showing a Toast.
Toast.makeText(this, "", Toast.LENGTH_SHORT)
.show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> list) {
// Some permissions have been granted
Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + list.size());
}
@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + list.size());
// (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
// This will display a dialog directing them to enable the permission in app settings.
if (EasyPermissions.somePermissionPermanentlyDenied(this, list)) {
new AppSettingsDialog.Builder(this).build().show();
}
}
}