I have a dialog that loads tabLayout with 5 sections and its content are loaded using ViewPager with View Pager adapter. Now, in one of the sections, I have to load images from the gallery. I have written the runtime permission, but I cannot use the callback of the permission as I have implemented this dialog in a class that doesn't have an activity. I have no idea how to implement the callback method of permissions in an activity-less class.
public void makePermissionRequest(){
if(ContextCompat.checkSelfPermission(showEditorActivity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(showEditorActivity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, permission_request_code);
}else{
fetchImagesFromDevice();
}
}
and for callback..
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case permission_request_code: {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.i("permission..link", "allowed");
fetchImagesFromDevice();
}else{
Log.i("permission..link", "denied");
if (ContextCompat.checkSelfPermission(showEditorActivity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(showEditorActivity, Manifest.permission.READ_EXTERNAL_STORAGE)) {
showMessageOKCancel("You need to allow access to your Internal Memory", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//log to find out answer..
if (which == -1) {
makePermissionRequest();
}
}
});
}
}
}
}
}
}