android - Runtime permission: shouldshowrequestpermissionrationale always returns false -
below code, called code getting runtime permission. in case "shouldshowrequestpermissionrationale returns false". cannot find solution why goind this. due run time permission alert not displayed. suggest me solution pls...
private void checkruntimepermission() { logger.infolog("checkruntimepermission"); if(activitycompat.checkselfpermission(this, permissionsrequired[0]) != packagemanager.permission_granted){ logger.infolog("checkruntimepermission first if"); if(activitycompat.shouldshowrequestpermissionrationale(welcomeactivity.this,permissionsrequired[0])){ logger.infolog("checkruntimepermission if"); //just request permission //show information why need permission alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("need multiple permissions"); builder.setmessage("this app needs camera , location permissions."); builder.setpositivebutton("grant", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dialog.cancel(); activitycompat.requestpermissions(welcomeactivity.this,permissionsrequired,permission_callback_constant); } }); builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dialog.cancel(); } }); builder.show(); }else{ logger.infolog("show request permission rationale false"); } } else { //you have permission, go ahead. logger.infolog("permission given already"); proceedafterpermission(); } }
the method invoking asking question "should show reason requesting permission?"
from docs "this method returns true if app has requested permission , user denied request."
https://developer.android.com/training/permissions/requesting.html
if value false, still want request permission don't need show alert dialog. so, in else block
activitycompat.requestpermissions(welcomeactivity.this,permissionsrequired,permission_callback_constant);
Comments
Post a Comment