Sketchware-Pro / Sketchware-Pro

Sketchware Pro's sources in Java. Now anyone can contribute to Sketchware Pro.
https://sketchware.pro
Other
863 stars 254 forks source link

File block is not working for android 10 or more #293

Closed kweethite closed 2 months ago

kweethite commented 2 years ago

when we use file block sketchware is automatically added file Permisson requests but it's only working for android android 9 or below if we want to request storage permission for android 10 need to add manual sorry my English is bad
whatever I know you will understand 😑😑

please add this Feacture in the future version of sketchware 🙂

DerGoogler commented 2 years ago

Read this here https://developer.android.com/about/versions/11/privacy/storage

JavkhlanK commented 2 years ago

Sketchware Pro automatically adds an attribute to AndroidManifest.xml so that current File Blocks work on Android 10.

On newer versions, storage access is a bit more restricted. You'd need another special permission (which must be enabled in Settings like the Access Usage Data permission and often can't be used by apps on Google Play) or Blocks with different code under-the-hood. Currently, that's not in focus by us.

DerGoogler commented 2 years ago

You can try this class.. idk if it works. Try your luck

package com.dergoogler.hentai.zero.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

/**
 * File Utilities
 *
 * @author mcharima5@gmail.com
 * @since 2018
 */
public class FileUtil {

    private static boolean mkdirs(File dir) {
        if (null == dir) {
            return false;
        }
        if (dir.exists()) {
            return true;
        }
        return dir.mkdirs();
    }

    @SuppressWarnings("BooleanMethodIsAlwaysInverted")
    public static boolean delete(File file) {
        if (null == file || !file.exists()) {
            return false;
        }
        return file.delete();
    }

    public static boolean exists(File file) {
        return file.exists();
    }

    public static String newFilename(String extension) {
        String name = DateTimeUtil.formatDate(new Date(), "yyyyMMdd_HHmmss");
        return name + "."  + extension;
    }

    public static File createFile(File dir, String...pathAndFilename) throws IOException {
        File file = dir;
        for (String path : pathAndFilename) {
            file = new File(file, path);
        }
        if (!mkdirs(file.getParentFile())) {
            throw new IOException("mkdirs failed...!!!!! " + dir);
        }
        if (exists(file)) {
            if (!delete(file)) {
                throw new IOException("delete failed...!!!!! " + file);
            }
        }
        if (file.createNewFile()) {
            return file;
        }
        return null;
    }

    public static void write(FileInputStream fin, FileOutputStream fos) throws IOException {
        try {
            byte[] buff = new byte[1024 * 4];   // 1MB = 1048576 = 1024 * 1024, 10KB = 10240 = 10 * 1024
            while (true) {
                int len = fin.read(buff);
                if (-1 == len) {
                    break;
                }
                fos.write(buff, 0, len);
            }
        }
        finally {
            IOUtil.closeQuietly(fin);
            IOUtil.closeQuietly(fos);
        }
    }

}
iyxan23 commented 2 years ago

You can try this class.. idk if it works. Try your luck

package com.dergoogler.hentai.zero.util;
...

sussy package name

khaled-0 commented 2 years ago

:mongass:

You can try this class.. idk if it works. Try your luck

package com.dergoogler.hentai.zero.util;
...

sussy package name

:monguss: suss

JavkhlanK commented 2 years ago

That class operates with just java.io.File, so it won't be any better than Sketchware's FileUtil.java.

DerGoogler commented 2 years ago

You can try this class.. idk if it works. Try your luck

package com.dergoogler.hentai.zero.util;
...

sussy package name

Just a normal package name 😐