I am currently working on an application that requires several \"dangerous\" permissions. So I tried adding \"ask for permission\" as required in Android Marshmallow(API Lev
To handle runtime permission google has provided a library project. You can check this from here https://github.com/googlesamples/easypermissions
EasyPermissions is installed by adding the following dependency to your build.gradle file:
dependencies {
compile 'pub.devrel:easypermissions:0.3.0'
}
To begin using EasyPermissions, have your Activity (or Fragment) override the onRequestPermissionsResult method:
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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 list) {
// Some permissions have been granted
// ...
}
@Override
public void onPermissionsDenied(int requestCode, List list) {
// Some permissions have been denied
// ...
}
}
Here you will get a working example how this library works https://github.com/milon87/EasyPermission