Whether you want to use GPS or Compass, Camera or the Internet, you will need to add permissions to your Qt app for Android because Android API uses a permission system for security reasons. It actually has other benefits such as helping with monitoring and app statistics and so on but I’m not going to discus that in this post.
If you need to add permissions to your Qt Android app then follow these steps.
- First of all I assume that you have already created an android app but you don’t know how to add permissions for it. So, start by building your Qt for Android project first.
- When you build a Qt project, a folder will be created by Qt to contain your build files. If you are using the default settings then this folder is located in the same folder where your project is located. It usually has a name similar to this: (Note that this is just an example and the folder name depends on the version and type of Qt build you are using but it has the same pattern)
- If you go to the build folder mentioned above, there is a folder named “android-build” inside it. Inside android-build you will find a file named AndroidManifest.xml, copy that file.
- Next, create a folder named “android-sources” inside your Qt project folder and copy AndroidManifest.xml there. (Note that your Qt project folder is the folder where your Qt PRO and source code CPP files etc. are located.)
- Now right click your project in Qt Creator and select Add Existing Files. And select AndroidManifest.xml from the android-sources folder to add it to your project.
Note that you should have this in “Other files” section of your project.
- Now you can start adding all permissions needed by your app. Don’t overuse it, just select any permission that your app really needs. To do this double click AndroidManifest.xml. You will see an screen appear at the right side of the Qt Creator window where you do the coding. This is Qt Creator’s Android Manifest editor. Use the combo box down below to select the permissions, and press Add button to add them to your project. Pressing Remove button will obviously remove the added permissions.
- Finally, open your Qt project (.PRO) file and append the following line at the bottom of it.
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
- Now when you run your Qt Android project it has the required permissions!