nabinbhandari / android-permissions Goto Github PK
View Code? Open in Web Editor NEWLibrary for easy handling of android run-time permissions.
Library for easy handling of android run-time permissions.
Hi. I am using your library in my app. I got a Runtime Exception only on some devices. I cant figure out why... Here's the log
`Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=6937, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.ytheekshana.deviceinfo/com.nabinbhandari.android.permissions.PermissionsActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.ActivityThread.deliverResults(ActivityThread.java:4926)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4969)
at android.app.ActivityThread.access$1600(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1850)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)`
In my fragment
`HorizontalScrollView scrollViewCamera = rootView.findViewById(R.id.scrollViewCamera);
cameraButtonGroup = rootView.findViewById(R.id.cameraButtonGroup);
recyclerCamera = rootView.findViewById(R.id.recyclerCamera);
Button btnCameraPermission = rootView.findViewById(R.id.btnCameraPermission);
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
btnCameraPermission.setVisibility(View.VISIBLE);
scrollViewCamera.setVisibility(View.GONE);
recyclerCamera.setVisibility(View.GONE);
} else {
btnCameraPermission.setVisibility(View.GONE);
scrollViewCamera.setVisibility(View.VISIBLE);
recyclerCamera.setVisibility(View.VISIBLE);
loadCameraAll();
}
btnCameraPermission.setOnClickListener(view -> Permissions.check(context, Manifest.permission.CAMERA, null, new PermissionHandler() {
@Override
public void onGranted() {
btnCameraPermission.setVisibility(View.GONE);
scrollViewCamera.setVisibility(View.VISIBLE);
recyclerCamera.setVisibility(View.VISIBLE);
loadCameraAll();
}
@Override
public void onDenied(Context context, ArrayList<String> deniedPermissions) {
}
}));`
Any fix for this ?
Happened in 4 devices with Android 6.0. Looks like this bug is only in Marshmallow devices.
Hi, i use your library in my library project and it works well. But, when i generate my library into aar format, and then included it to my app project, it does not work.
I've found this error >> java.lang.ClassNotFoundException: Didn't find class "com.nabinbhandari.android.permissions.PermissionHandler"
Thank you
The dialog that pops up with the rationale looks kind of funny on my device. Is there any way to center that text? I can't seem to find the xml.
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2421)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2481)
at android.app.ActivityThread.access$900 (ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1349)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:174)
at android.app.ActivityThread.main (ActivityThread.java:5440)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
Caused by: java.lang.NullPointerException:
at android.content.pm.PackageManager.buildRequestPermissionsIntent (PackageManager.java:2659)
at android.app.Activity.requestPermissions (Activity.java:3860)
at com.nabinbhandari.android.permissions.PermissionsActivity.onCreate (PermissionsActivity.java:72)
at android.app.Activity.performCreate (Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2374)
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2955)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
at android.os.Handler.dispatchMessage (Handler.java:105)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6938)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
Caused by: java.lang.IllegalArgumentException:
at android.content.pm.PackageManager.buildRequestPermissionsIntent (PackageManager.java:4007)
at android.app.Activity.requestPermissions (Activity.java:4458)
at com.nabinbhandari.android.permissions.PermissionsActivity.onCreate (PermissionsActivity.java:72)
at android.app.Activity.performCreate (Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2908)
i'm facing issue on android 13 i have found that setFinishOnTouchOutside is not working in android 13 devices , is anyone know about that please give an update.
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:1072)
at android.app.ContextImpl.startActivity(ContextImpl.java:1041)
With Android 9, you cannot start an activity from a non-activity context unless you pass the intent flag FLAG_ACTIVITY_NEW_TASK. If you attempt to start an activity without passing this flag, the activity does not start, and the system prints a message to the log.
Hi,
I have version 3.8
the first time I require the permission message is not showing but from the second time message is showing on all requests.
and on some devices not showing the rational message at all.
I am using kotlin by the way.
In may this library won't be available from JCenter: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Please migrate this library to some other repository
Hi,
targetSdkVersion is 27 in this library and for uploading apps to playstore this library needs to have targetSdkVersion = 29 at least.
I will be thankfull if you could change it, so wen use it and upload our app
Issue facing in android api level 33.
I found a link for this library on stack overflow. I really like how clean it is but I have one problem.
When I request permissions, I only see the dialog that says that the user has previously denied the permission. This is with a fresh install on the emulator. Any ideas what I might be doing wrong?
target and compile SDK is 28
minSDK is 19
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
String rationale = getString(R.string.external_write_rational);
Permissions.check(getContext(), permissions, rationale, null, new PermissionHandler() {
@Override
public void onGranted() {}
});
There is an opportunity to call permission request right from the Fragment
:
void requestPermissions(@NonNull String[] permissions, int requestCode)
and get a result in the same Fragment
:
onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
in android.support.v4.app.Fragment. Does your library allow this too?
Hi.
I moved back to my side project and even updated to version 3.7 but I don't think it is about the version. I have Android 7.0 and using it like this in my Activity.
Permissions.check(this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
R.string.permission_required_body,
Permissions.Options()
.setSettingsDialogTitle(getString(R.string.permission_required_title))
.setSettingsDialogMessage(getString(R.string.permission_blocked_body))
.setRationaleDialogTitle(getString(R.string.permission_required_title)),
permissionHandler)
and instead of seeing the custom dialog, I see the native permission dialog to allow/deny permission but without the "Don't ask again" option. It happens irrespective of GPS is already enabled or disabled.
Can you please look into this matter because I am writing my blog post on a use case which uses your lib and now I am worried about this strange behaviour which was not there when I last worked on it 2 months ago.
Hi, this library don't work for me.
Can't ask for multiple permissions at the same time.
It asks only for the first one in the array.
I'm trying to allow both the READ and WRITE storage permissions at once, but without any success.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blah.blah.debug/com.nabinbhandari.android.permissions.PermissionsActivity}: java.lang.IllegalArgumentException: permission cannot be null or empty
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: permission cannot be null or empty
at android.content.pm.PackageManager.buildRequestPermissionsIntent(PackageManager.java:3544)
at android.app.Activity.requestPermissions(Activity.java:4381)
at com.nabinbhandari.android.permissions.PermissionsActivity.onCreate(PermissionsActivity.java:72)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
I am observing on Permission Checks in my background service. While service is running and app is removed from recent apps, If I try to revoke permission it shows the dialog which makes total sense. But at the same time it also make the App alive in background and irrespective of pressing "Cancel" or "Ok", if I bring the app to foreground it crashes. In that state, I don't know why lib is getting null or empty permission.
I am using app in production environment so it's kind of critical for me. if you have more questions to understand the problem I would be more than happy to help you out.
Hi,
I was suffering of issue #11 and fixed it by using setCreateNewTask().
But I can surely not be the only one calling the check from a fragment in example.
In IMHO the option is hidden to deep and is not well documented enough.
But my mayor issue is that check function only supports Options parameter in combination with String[] not with String. Can you change that? Of course I can use String[] permissions = {single permission}
at android.app.ContextImpl.startActivity (ContextImpl.java:672)
at android.app.ContextImpl.startActivity (ContextImpl.java:659)
at android.content.ContextWrapper.startActivity (ContextWrapper.java:331)
at com.nabinbhandari.android.permissions.Permissions.check (Permissions.java:121)
at nigeria.comedy.sound.effect.meme.Player$2.onClick (Player.java:83)
at android.view.View.performClick (View.java:5205)
at android.view.View$PerformClick.run (View.java:21162)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5452)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:762)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:652)
Is there any way we can change color of text or dialog color. On sony tv it does not look good, i can send you image if you want to see
for min sdk 16 it does't show the permissoins dialog. i dont know why. but it works for 15 and the previous ones.
Hey there,
I recently updated my Test Pixel 3 to Android Q Beta 3 and I'm requesting the Location (Fine) Permission within my app.
Unfortunately the process crashes after I accept the permission. Within the logs logs I can't really see the cause:
https://gist.github.com/chrjsorg/334223e49aff5ccf1ff129657d7aff1f
if (!BuildConfig.DEBUG) Permissions.disableLogging()
Permissions.check(this, Array(1) { permission },
getString(rationale),
Permissions.Options().setRationaleDialogTitle("string")
.setSettingsDialogTitle("string2")
.setSettingsDialogMessage("string3")
.setSettingsText("string3"),
object : PermissionHandler() {
override fun onDenied(context: Context?, deniedPermissions: ArrayList<String>?) {
}
override fun onGranted() {
grantedCallback()
}
})
Do you have any idea? I'd be happy to support you with more informations.
My app runs a service on a separate process, defined in the manifest as such:
<service
android:name=".ManagerService"
android:process=":ManagerProcess"/>
This service requires permissions on certain user actions, and I'm requesting them in the following way:
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA};
Permissions.Options options = new Permissions.Options()
.setRationaleDialogTitle("test rationale")
.setSettingsDialogTitle("test title")
.setSettingsDialogMessage("test settings")
.setSettingsText(context.getString(R.string.action_settings))
.setCreateNewTask(true); //Needs to create a task because we're asking for permissions outside of activity context
final String rationale = "placeholder";
Permissions.check(context, permissions, rationale, options, new PermissionHandler() {
@Override
public void onGranted() {
//TODO
Log.d("test4636", "granted");
Toast.makeText(context, "granted", Toast.LENGTH_LONG).show();
}
@Override
public void onDenied(Context context, ArrayList<String> deniedPermissions) {
//TODO
Log.d("test4636", "denied");
Toast.makeText(context, "denied", Toast.LENGTH_LONG).show();
for (String perm : deniedPermissions) {
Log.d("test4636", perm);
}
}
});
With this setup, onGranted() and onDenied() are never called. Removing android:process=":ManagerProcess"
from the service solves the issue, but I can't implement it that way because the service has to be running on a separate process due to other requirements. Is there any workaround to getting the callbacks to work when using android:process?
When I deny the all permissions I requested:
First time round - Opens a dialog with the user specific method.
Second time round - Quits and no callback methods are triggered.
My goal is to continue to ask the user to accept the permissions or block them outright.
it is weird, but i fell when i check, "set not to ask again" for permission"WRITE_EXTERNAL_STORAGE", its likely saved in project, so when i want to call it again in another phone, it still show setting dialog, and i cannot get "WRITE_EXTERNAL_STORAGE" permission in every phone
I can find 1.0 in bintray, but that's the only version I can find anywhere. It looks like the latest version is 3.7?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.