Search code examples
nativescriptnativescript-angular

Runtime request permission in NativeScript Android app


I code an application in Native Script and I need to use requestPermission after first launch app. I know how to use request permission, but I don't know how to make it work after first running the application. Where I must use request-permission function in app ? In ngOnInit () ?


Solution

  • You may use nativescript-permissions plugin to acquire runtime permissions on Android.

    Use hasPermission(permissionName); method to know whether your app already has the permission Or you are yet to acquire it.

    Generally it's recommended to ask for permission only when it's absolute necessary. For example, if you want to access micro phone to record anything you would request for permission only when user tries to record one, not upon launch.

    You could still ask permissions upon launch, that would work. But in my opinion that could be annoying to the user. May be he is not intended to use that particular feature of the app but just the rest.