Thanks for the hint, I will add that.Copying a folder from internal flash (/mnt/sdcard) does not work.
Currently this isn't supported in plugins, but I will try to add it to the next version if possible.Copying files from the lan (SMB) does not work.
For anyone who wants to do this too, here is a class which you can use to write to the SD-Card. Feel free to use it in your own programs.
Code: Select all
package com.ghisler.android.TotalCommander;
import java.io.OutputStream;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
public class MediaFileFunctions {
@SuppressLint({ "NewApi", "NewApi" })
private static Uri getFileUri(Context context,String fullname) {
// Note: check outside this class whether the OS version is >= 11
Uri uri=null;
Cursor cursor=null;
ContentResolver contentResolver=null;
try{
contentResolver=context.getContentResolver();
if (contentResolver==null)
return null;
uri=MediaStore.Files.getContentUri("external");
String[] projection=new String[2];
projection[0]="_id";
projection[1]="_data";
String selection="_data = ? "; // this avoids SQL injection
String[] selectionParams=new String[1];
selectionParams[0]=fullname;
String sortOrder="_id";
cursor=contentResolver.query(uri, projection, selection, selectionParams, sortOrder);
if (cursor!=null) {
try {
if (cursor.getCount()>0) { // file present!
cursor.moveToFirst();
int dataColumn=cursor.getColumnIndex("_data");
String s=cursor.getString(dataColumn);
if (!s.equals(fullname))
return null;
int idColumn=cursor.getColumnIndex("_id");
long id=cursor.getLong(idColumn);
uri=MediaStore.Files.getContentUri("external",id);
} else { // file isn't in the media database!
ContentValues contentValues=new ContentValues();
contentValues.put("_data",fullname);
uri=MediaStore.Files.getContentUri("external");
uri=contentResolver.insert(uri,contentValues);
}
} catch (Throwable e) {
uri=null;
}
cursor.close();
}
} catch (Throwable e) {
uri=null;
}
return uri;
}
public static OutputStream getOutputStreamViaContentProvider(Context context,String fullname) {
Uri uri=getFileUri(context,fullname);
if (uri==null)
return null;
try {
ContentResolver resolver=context.getContentResolver();
return resolver.openOutputStream(uri);
} catch (Throwable e) {
return null;
}
}
public static boolean deleteViaContentProvider(Context context,String fullname) {
Uri uri=getFileUri(context,fullname);
if (uri==null)
return false;
try {
ContentResolver resolver=context.getContentResolver();
// change type to image, otherwise nothing will be deleted
ContentValues contentValues=new ContentValues();
int media_type=1;
contentValues.put("media_type", media_type);
resolver.update(uri,contentValues,null,null);
return resolver.delete(uri,null,null)>0;
} catch (Throwable e) {
return false;
}
}
public static boolean mkDirViaContentProvider(Context context,String fullname) {
String fileName;
Uri uri;
ContentResolver resolver;
try {
resolver=context.getContentResolver();
fileName = strcatslash(fullname)+"ghisler_temp.jpg";
ContentValues contentValues=new ContentValues();
contentValues.put("_data", fileName);
uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
} catch (Throwable e) {
return false;
}
if (uri!=null) {
try {
resolver.delete(uri,null,null);
} catch (Throwable e) {
}
return true;
} else
return false;
}
public static String strcatslash(String dir) {
if (dir.length()>0 && !dir.endsWith("/"))
return dir+"/";
else
return dir;
}
}
Code: Select all
boolean ok=true;
OutputStream g = null;
try {
g = new FileOutputStream(fulltrg);
} catch (Exception e1) {
ok = false;
}
if (!ok && getOsVersion()>=11 && fulltrg.startsWith("/mnt")) {
g=MediaFileFunctions.getOutputStreamViaContentProvider(this,fulltrg);
Code: Select all
public static int getOsVersion() {
try {
java.lang.reflect.Field osField = android.os.Build.VERSION.class.getDeclaredField("SDK_INT");
osField.setAccessible(true);
int myBuild = osField.getInt(android.os.Build.VERSION.class);
return myBuild;
} catch (Exception e) {
return 3;
}
}