Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied on Huawei when trying to save file #21

Open
ursaklunIX opened this issue Aug 3, 2023 · 1 comment
Open

Permission denied on Huawei when trying to save file #21

ursaklunIX opened this issue Aug 3, 2023 · 1 comment

Comments

@ursaklunIX
Copy link

Which platform(s) does your issue occur on?

  • Huawei, Huawei P40 lite, EMUI 12.0.0

Please, provide the following version numbers that your issue occurs with:

  • CLI: 8.4.0

Please, tell us how to recreate the issue in as much detail as possible.

The problem is when I try to save file in Huawei device. Function "requestPermission('storage')" returns
{ "android.permission.READ_EXTERNAL_STORAGE": "never_ask_again", "android.permission.WRITE_EXTERNAL_STORAGE": "never_ask_again" }
without asking user to grant permission, but then when i try to create new file on external storage, i get the following error:
Error: Uncaught (in promise): Error: java.io.IOException: Permission denied

I have no problem on android devices (android version 14, 12, 11 and 7).

Is there any code involved?

requestPermission("storage").then((response) => {
  const bytes = android.util.Base64.decode(pdfDocument.dokument, 0);
  const path = `${android.os.Environment.getExternalStoragePublicDirectory(
    android.os.Environment.DIRECTORY_DOWNLOADS,
  ).getAbsolutePath()}/${pdfName}`;

  let toFile = File.fromPath(`${path}.pdf`);

  let i = 1;
  while (toFile.size > 0) toFile = File.fromPath(`${path} (${i++}).pdf`);

  toFile.writeSync(bytes);

  setTimeout(() =>
    this.modalService.openInfo({
      text: "DOCUMENT.save_to_device_successful",
      okText: "DOCUMENT.save_to_device_successful_ok",
    }),
  );
});

AndroidManifest.xml

        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
	<uses-permission android:name="android.permission.INTERNET"/>
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
	<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
	<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
	<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>

	<application
		android:name="com.tns.NativeScriptApplication"
		android:allowBackup="true"
		android:icon="@mipmap/icon"
		android:label="@string/app_name"
		android:theme="@style/AppTheme"
		android:hardwareAccelerated="true"
		android:requestLegacyExternalStorage="true"
	>
            ...
        </application>
@farfromrefug
Copy link
Member

@ursaklunIX sorry i dont have such a phone so i cant really help. But i would try to see what android version it is running as newer android versions dont use WRITE_EXTERNAL_STORAGE anymore and you need to use SAF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants