NeoLSN / cordova-plugin-android-permissions

This plugin is designed for supporting Android new permissions checking mechanism.
Apache License 2.0
273 stars 175 forks source link

uses-feature and camera request in Ionic 6 #119

Open cr1979 opened 1 year ago

cr1979 commented 1 year ago

Hello, I have a problem with this Plugin V1.1.5. I try to request camera permission, but it is not showing any prompt, and it always returns hasPermission = false. I'm currently using Ionic 6 with Angular 12, Cordova 8.1.0, Android SDK 31, and @awesome-cordova-plugins/android-permissions Version 6.2.0. I have to use uses-feature because it is optional in my application, and with uses-permission the google play store is filtering out our app for devices without a camera.

This is my code that I execute by clicking a button:

  import { AndroidPermissions } from '@awesome-cordova-plugins/android-permissions/ngx';

  constructor(..., private androidPermissions: AndroidPermissions, ...) {}

  public async scan() {
      let permission = await this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.CAMERA);

      if (permission.hasPermission) {
        console.log('Permission granted...');
      } else {
        console.log('Asking for Permission...');
        permission = await this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA);
      }

      if (permission.hasPermission) {
        console.log('Permission granted...');
      } else {
        console.log('Permission not granted...');
      }
}

in the .module.ts:

import { AndroidPermissions } from '@awesome-cordova-plugins/android-permissions/ngx';

@NgModule({
  declarations: [...],
  imports: [...],
  exports: [...],
  providers: [AndroidPermissions],
 })

my AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="22120103" android:versionName="2212.01.03" package="de.xxx.xxx" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="sensor" android:theme="@android:style/Theme.Translucent" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.appupdate.provider" android:exported="false" android:grantUriPermissions="true" android:name="com.vaenow.appupdate.android.GenericFileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/appupdate_paths" />
        </provider>
        <uses-library android:name="com.datalogic.device" android:required="false" />
        <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
        <activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />
    </application>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.honeywell.decode.permission.DECODE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />
</manifest>

I thank you in advance for any help.

NeoLSN commented 1 year ago

If you didn't use use-feature you can request camera request, that is a policy of android. I don't have any idea to solve your issue.

cr1979 commented 1 year ago

Hello, thank you for your help. So I can use only uses-permission? On Android, I found that:

If a feature is explicitly declared as not being required, Google Play does not add the feature to the list of required features. For that reason, an explicitly declared non-required feature is never considered when filtering the application. Even if the device does not provide the declared feature, Google Play will still consider the application compatible with the device and will show it to the user unless other filtering rules apply. For example:

<uses-feature android:name="android.hardware.camera" android:required="false" />

And this is important: Note: When declaring a feature, remember that you must also request permissions as appropriate. For example, you must still request the CAMERA permission before your application can access the camera API. Requesting the permission grants your application access to the appropriate hardware and software. Declaring the features used by your application ensures proper device compatibility.

So I have to request permission.

cr1979 commented 1 year ago

@NeoLSN I tried it without any uses-permission and uses-feature same behavior, no prompt, and as a result hasPermission=false. So in other words the plugin is currently useless.

So I tried it with that AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="22120103" android:versionName="2212.01.03" package="de.all4cloud.scan4cloud" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="sensor" android:theme="@android:style/Theme.Translucent" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.appupdate.provider" android:exported="false" android:grantUriPermissions="true" android:name="com.vaenow.appupdate.android.GenericFileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/appupdate_paths" />
        </provider>
        <uses-library android:name="com.datalogic.device" android:required="false" />
        <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
        <activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />
    </application>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.honeywell.decode.permission.DECODE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</manifest>

if I use uses-permission, I will be asked for permission without any plugin, but it is not appearing in the google play store for smartphones without a camera.