PERMISSÃO
PERMISSÃO
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent
_data) {
super.onActivityResult(_requestCode, _resultCode, _data);
if (_requestCode == new_folder){
if (_resultCode == Activity.RESULT_OK) {
if (_data != null) {
final Uri uri2 = _data.getData();
if (Uri.decode(uri2.toString()).endsWith(":")) {
SketchwareUtil.showMessage(getApplicationContext(), "Operação falhou");
askPermission(uri2.toString());
}
else {
final int takeFlags = i.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri2, takeFlags);
} else {
}
} else {
}
}
if (_requestCode == 2000) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
} else {
}
}
}
public void RequestPermission_Dialog() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
try {
Intent intent = new
Intent(android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse(String.format("package: ", new
Object[]{getApplicationContext().getPackageName()})));
startActivityForResult(intent, 2000);
} catch (Exception e) {
Intent obj = new Intent();
obj.setAction(android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
startActivityForResult(obj, 2000);
}
} else {
androidx.core.app.ActivityCompat.requestPermissions(MainActivity.this,
new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE);
}
}
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
i.setAction(Intent.ACTION_OPEN_DOCUMENT_TREE);
i.putExtra(android.provider.DocumentsContract.EXTRA_INITIAL_URI, Uri.parse(_uri));
startActivityForResult(i, new_folder);
}
if ( _path.endsWith("/")) {
_path = _path.substring(0, _path.length()-1);
}
if (_path.contains("/sdcard/")) {
uriFor2 = _path.replace("/sdcard/", "").replace("/", "%2F");
if (uriFor2.substring(uriFor2.length()-1,
uriFor2.length()).equals("/")) {
}
else {
if (_path.contains("/storage/") && _path.contains("/emulated/"))
{
uriFor2 = _path.replace("/storage/emulated/0/",
"").replace("/", "%2F");
if (uriFor2.substring(uriFor2.length()-1,
uriFor2.length()).equals("/")) {
}
else {
}
}
return uriFor1 = uriFor1 + uriFor2;
}
if ( _path.endsWith("/")) {
_path = _path.substring(0, _path.length()-1);
}
if (_path.contains("/sdcard/")) {
uriFor2 = _path.replace("/sdcard/", "").replace("/", "%2F");
if (uriFor2.substring(uriFor2.length()-1,
uriFor2.length()).equals("/")) {
}
else {
if (_path.contains("/storage/") && _path.contains("/emulated/"))
{
uriFor2 = _path.replace("/storage/emulated/0/",
"").replace("/", "%2F");
if (uriFor2.substring(uriFor2.length()-1,
uriFor2.length()).equals("/")) {
}
else {
}
}
return uriFor1 = uriFor1 + uriFor2;
}
ContentResolver content =
getApplicationContext().getContentResolver();
input = getApplicationContext().getAssets().open(assetFilename);
output = content.openOutputStream(targetUri);
SketchwareUtil.showMessage(getApplicationContext(), "50%");
}catch(Exception e){
return true;
}
} catch (java.io.IOException e) {
}
final ArrayList<String> str = new ArrayList<>(Arrays.asList(files));
int nn = 0;
for(int _repeat12 = 0; _repeat12 < (int)(str.size()); _repeat12++) {
try {
Uri mUri = Uri.parse(pathToRealUri(_out));
androidx.documentfile.provider.DocumentFile dFile =
androidx.documentfile.provider.DocumentFile.fromTreeUri(getApplicationContext(),
mUri);
Uri mUri2 = Uri.parse(mUri.toString()+ "%2" +
fileName);
androidx.documentfile.provider.DocumentFile dFile2 =
androidx.documentfile.provider.DocumentFile.fromTreeUri(getApplicationContext(),
mUri2);
try {
androidx.documentfile.provider.DocumentFile file =
dFile.findFile(fileName);
android.provider.DocumentsContract.deleteDocument(getApplicationContext().getConten
tResolver(), file.getUri());
android.provider.DocumentsContract.deleteDocument(getApplicationContext().getConten
tResolver(), mUri2);
} catch (FileNotFoundException e) {
} catch (Exception e2) {
}
if (copyAsset(_folder+"/"+fileName, mUri)) {
SketchwareUtil.showMessage(getApplicationContext(), "Falha");
break;
}
nn++;
}
try {
String fileN = Uri.parse(copy.getPath()).getLastPathSegment();
}
} catch (java.io.FileNotFoundException e) {
e.printStackTrace();
} catch (java.io.IOException e) {
e.printStackTrace();
} finally {
try {
inStream.close();
outStream.close();
return true;
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
return false;
}
🔴 2° PERMISSÃO 🔴
checkPermission(pathToRealUri(path))
🔴 3° PERMISSÃO 🔴
copyAssetFolder("file", path);
🔴 4° PERMISSÃO 🔴
askPermission(pathToUri(path));