1

Im building an application which should run on a hardware which doesn't have any screens. To run the application I need two permissions: Camera and writing to storage. Since my application doesn't have any UIs, and the device doesn't have any way of showing UIs, I'm wondering how to grant permissions for the application.

In this particular application users already know that the device will be taking images when user presses a button. So from users perspective, no need to grant permission explicitly.

Thanks in advance.

KTB
  • 1,499
  • 6
  • 27
  • 43
  • there is no way for regular android. Only for Android-things. – Vladyslav Matviienko Aug 10 '17 at 08:45
  • Check this [how-to-request-permissions-from-a-service-in-android-marshmallow](https://stackoverflow.com/questions/32292675/how-to-request-permissions-from-a-service-in-android-marshmallow) – ELITE Aug 10 '17 at 08:54

2 Answers2

0

There is no way to add permissions at runtime, they must be explicit in the AndroidManifest because they need to be presented at installation to the Android User.

May I suggest you take a look at the following post: Permission issue while starting a service from android

Global access to a service can be enforced when it is declared in its manifest's tag. By doing so, other applications will need to declare a corresponding element in their own manifest to be able to start, stop, or bind to the service.

As of GINGERBREAD, when using Context.startService(Intent), you can also set Intent.FLAG_GRANT_READ_URI_PERMISSION and/or Intent.FLAG_GRANT_WRITE_URI_PERMISSION on the Intent. This will grant the Service temporary access to the specific URIs in the Intent. Access will remain until the Service has called stopSelf(int) for that start command or a later one, or until the Service has been completely stopped. This works for granting access to the other apps that have not requested the permission protecting the Service, or even when the Service is not exported at all.

In addition, a service can protect individual IPC calls into it with permissions, by calling the checkCallingPermission(String) method before executing the implementation of that call.

See the Security and Permissions document for more information on permissions and security in general.

Gustavo Gomes
  • 317
  • 5
  • 13
0

Making a transparent activity without having UI (no any xml layout) and do the code for android marshmallow permissions. When the your application run then call this activity from service and user will see permission only when app trigger from any where while from hardware or anywhere. while app is open transparent activity is open and user can give the permission.

  • but the problem is there's no screen on the device. so there's no way user can see permissions. – KTB Aug 13 '17 at 10:46
  • Your Application has service only right... call transparent activity from that service start your app . Means when the application trigger something(start service) . Simple: step 1 You can make a transparent activity without UI and code for permission what you want right. Step 2. call this Activity from service got it (You can start activity from service no need any UI screen). And when this activity call only permission popup comes first time when app embedded in device. – Sachin Chauhan Aug 16 '17 at 09:33