tajchert / nammu Goto Github PK
View Code? Open in Web Editor NEWPermission helper for Android M - background check, monitoring and more
License: MIT License
Permission helper for Android M - background check, monitoring and more
License: MIT License
When you ask a permission, android shows a popup, if at this moment app go to background and than back to foreground
PermissionCallback will trigger permissionsGranted but actually not. It happens because at this moment will call onRequestPermissionsResult with empty grantResults.
How we can see, method verifyPermissions return true by default, and how result wrong trigger of permissionGranted.
I think this method should return false by default.
fun verifyPermissions(grantResults: IntArray): Boolean {
for (result in grantResults) {
if (result != PackageManager.PERMISSION_GRANTED) {
return false
}
}
return true
}
AskForSpecialPermission method was removed in 1.4.0 due to memory leaks with Fragment declared anonymously inside. Help in that area is wanted.
Will this lib be further developed so that it also works with Android 11, where the authorization concept is completely different?
Will this lib be further developed so that it also works with Android 11, where the authorization concept is completely different?
I also use this lib, but the permissions don't work on smartphones with Android 11 and higher.
verifyPermissions ,this method I think it should return flase default.
if i askForPermission twice with one Permission,it will return true the first time.
Nammu.checkCamera()
is there but is kept private as this results in crash in sample app when Camera in Fragment is launched:
java.lang.RuntimeException: set display orientation failed
at android.hardware.Camera.setDisplayOrientation(Native Method)
at pl.tajchert.nammusample.camera.CameraPreview.surfaceChanged(CameraPreview.java:97)
at android.view.SurfaceView.updateWindow(SurfaceView.java:591)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2030)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
To fix this probably there is needed some release call or use of Camera2 API.
I couldn't find any method that doesn't open Camera preview and require permission to use a test (so only async methods which are not perfect).
For now Camera permission can be check only with Activity instance with new runtime permission API.
Help needed - if you know solution to that :)
Very nice idea to put all granted permissions into one collection.
I am just wondering 'when' to check the permissions. Gathering data during onCreate
in Application
class results with a fixed collection. My idea would be to check for permissions using ActvityLifecycleMonitor
after every onResume
?
For Java interoperability, please add @JvmStatic annotations on static functions.
in version 1.1.1 the only method signatures for askForPermission are the following
askForPermission(Activity activity, String permission, PermissionCallback permissionCallback)
askForPermission(Activity activity, String[] permissions, PermissionCallback permissionCallback)
There is no askForPermission for Fragment as shown in the sample app
Add the attached xml to automatically show in https://github.com/mikepenz/AboutLibraries
Will be done as soon as official API 23 (or so for Android M) is release - since then some thing might change as this is only a preview.
Also other problem is lack of targetSdkVersion="android-MNC" on Maven etc. which is not recognized.
This method is helpful as well. Why it has to be private. Unlike the other askForPermission for activity, it allow both single and multi permissions request. Is there any concern behind?
private static void askForPermission(Fragment fragment, String[] permissions, PermissionCallback permissionCallback) {
if (permissionCallback != null) {
if (hasPermission(fragment.getActivity(), (String[])permissions)) {
permissionCallback.permissionGranted();
} else {
PermissionRequest permissionRequest = new PermissionRequest(new ArrayList(Arrays.asList(permissions)), permissionCallback);
permissionRequests.add(permissionRequest);
fragment.requestPermissions(permissions, permissionRequest.getRequestCode());
}
}
}
It should be clarified in the README to use Application context.
While trying to use the app, I noticed that the Fragment parameter is a support library Fragment.
I am using regular fragments since my app only supports a fairly high API.
is it possible to add support for regular fragments?
Hey, now that the sdk is out, could you release it on jcenter?
Cheers,
How to differentiate between the permission that I am calling is first time or user have selected on the never asked again.
In sample you have mentioned this thing.
@OnClick(R.id.buttonLocation) public void clickButtLocation() { if (Nammu.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION)) { boolean hasAccess = Tools.accessLocation(this); Toast.makeText(this, "Access granted fine= " + hasAccess, Toast.LENGTH_SHORT).show(); } else { if (Nammu.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { //User already refused to give us this permission or removed it //Now he/she can mark "never ask again" (sic!) Snackbar.make(mLayout, "Here we explain user why we need to know his/her location.", Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() { @Override public void onClick(View view) { Nammu.askForPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION, permissionLocationCallback); } }).show(); } else { //First time asking for permission // or phone doesn't offer permission // or user marked "never ask again" Nammu.askForPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION, permissionLocationCallback); } } }
Here in comments you have mentioned
First time asking permission
or user marked "never ask again."
I want to know when user selected never asked again and proceed further
Error:Execution failed for task ':processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 15 declared in library [com.github.tajchert:nammu:1.0.0]
Can this library have minSdkVersion be 14 or lower?
The functions permissionGranted() and permissionRefused() aren't executed when the permission is granted or refused for the first time.
They will only execute after restarting the app.
Is there any way to get them executed without restarting the app.
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.