Why Don't We Need Permissions for Qt Applications on Android?



  • Hi;
    I wrote Android native (Java) code for WebView:

    import android.webkit.WebView;
    ...
    WebView webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("https://qt.io/");
    ...
    

    We need this permission to run the code:

    <uses-permission android:name="android.permission.INTERNET" />
    

    I wrote same application with Qt 5.x:

    import QtWebView 1.1
    ...
    WebView {
      id: webView
      anchors.fill: parent
      url: "https://qt.io/"
    }
    ...
    

    But we don't need the internet permission to run the Qt application. I'm wondering, why don't we need permissions for Qt applications on Android? Thanks.


  • Qt Champions 2016

    @Ibrahim take a look at the generated AndroidManifest inside your build dir
    there you'll see all permissions Qt has inserted



  • @ekkescorner thanks. I found permissions into build-QtAndroid-Android_for_x86_GCC_4_9_Qt_5_8_0_2f23f9-Debug/android-build/AndroidManifest.xml. Then I removed all WebView components from my project and I removed all permissions from build-QtAndroid-*/android-build/AndroidManifest.xml. But when I built my project, I always see this permissions:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

    Whereas my project doesn't need permissions:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
    
      Text {
        id: txt
        anchors.centerIn: parent
        text: qsTr("Hello World!")
      }
    }
    

    How can I remove unnecessary permissions from my project?


  • Qt Champions 2016

    @Ibrahim you should copy the templates to your project
    Build Android APK
    copy templates

    this copies the templates inside your project

    in your .pro
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    tells Qt where your android files are living

    go into this folder, open AndroidManifest and change the default behaviour
    all is explained there:

        <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
             Remove the comment if you do not require these default permissions. -->
        <!-- %%INSERT_PERMISSIONS -->
    

    BTW: you should read the documentation: http://doc.qt.io/qtcreator/creator-deploying-android.html
    scroll down to Editing Manifest Files - there you'll find all the needed informations


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.