TeamAmaze / AmazeFileManager

Material design file manager for Android
https://teamamaze.xyz
GNU General Public License v3.0
5.31k stars 1.57k forks source link

Can not get write access of external SD card on some device #183

Closed wuliou closed 8 years ago

wuliou commented 9 years ago

I use Amaze File Manager on my LG G Pro 2 (Android 5.0.1) to replace built-in file manager, when I first time copy files to external SD card, it will pop out an dialog asking for writing permission, so I can manipulate file on external SD card.

But when I wanna use Amaze File Manger on my Acer A3-A30 tablet (Android 5.0.2, and had no built-in file manager), the dialog didn't pop out, so the file disappeared after copy, just like doing in Android 4.4 phones.
I was wondering is this cause by the path difference of these two devices?

LG G Pro 2:
built-in SD: /storage/sdcard0/
External SD: /storage/external_SD/

Acer A3-A30:
built-in SD: /storage/sdcard0/
External SD: /storage/sdcard1/

arpitkh96 commented 9 years ago

I need your help solving this problem. Try this apk and tell me the messages displayed on the screen while copying(if any) https://drive.google.com/file/d/0B7y8VGv6MgR5YzMwdTRCQ3pBa3c/view?usp=docslist_api

PS-don't spam the forums. I have seen your posts already at many places. Just be patient. Not always we are free to reply or help you

wuliou commented 9 years ago

There were no messages displayed while copying files to the external SD card.(and the file disappeared also.)

arpitkh96 commented 9 years ago

File disappeared even while copying?

wuliou commented 9 years ago

Yes. the file even not showed up while copying.

arpitkh96 commented 9 years ago

Try this. Same thing, tell me the messages https://drive.google.com/file/d/0B7y8VGv6MgR5UmozdEFkVEhJMVU/view?usp=docslist_api

wuliou commented 9 years ago

The app crashed on launch. Here's the log:

09-17 21:10:27.204  15716-15716/? I/art﹕ Late-enabling -Xcheck:jni
09-17 21:10:27.549  15716-15716/com.amaze.filemanager D/AndroidRuntime﹕ Shutting down VM
09-17 21:10:27.550  15716-15716/com.amaze.filemanager E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.amaze.filemanager, PID: 15716
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amaze.filemanager/com.amaze.filemanager.activities.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.clans.fab.FloatingActionButton.setColorNormal(int)' on a null object reference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5219)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.clans.fab.FloatingActionButton.setColorNormal(int)' on a null object reference
            at com.amaze.filemanager.activities.MainActivity.onCreate(MainActivity.java:525)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5219)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I took some time to read the source code. I think that the environment variable method dose not work on the A30 tablet. The dump of A30's env:

_=/system/bin/printenv
EMULATED_STORAGE_SOURCE=/mnt/shell/emulated
ANDROID_DATA=/data
BOOTCLASSPATH=/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/apache-xml.jar:/system/framework/com.intel.config.jar:/system/framework/com.intel.multidisplay.jar
PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
LOOP_MOUNTPOINT=/mnt/obb
MESA_EXTENSION_OVERRIDE=+GL_OES_EGL_image_external -GL_ARB_framebuffer_object
ANDROID_ROOT=/system
force_s3tc_enable=true
EMULATED_STORAGE_TARGET=/storage/emulated
ANDROID_STORAGE=/storage
ANDROID_SOCKET_adbd=11
EXTERNAL_STORAGE=/storage/emulated/legacy
ANDROID_ASSETS=/system/app
LD_PRELOAD=libsigchain.so
RANDOM=22574
ASEC_MOUNTPOINT=/mnt/asec
ANDROID_PROPERTY_WORKSPACE=9,0
SYSTEMSERVERCLASSPATH=/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar
ANDROID_BOOTLOGO=1
wuliou commented 9 years ago

Just make a hardcoded fix to make external write access works on my device. In FileUtil :

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public static String getExtSdCardFolder(final File file,Context context) {
        //String[] extSdPaths = getExtSdCardPaths(context);
        String[] extSdPaths = {"/storage/sdcard1"}; //hardcoded for Acer A3-A30
        try {
            for (int i = 0; i < extSdPaths.length; i++) {
                if (file.getCanonicalPath().startsWith(extSdPaths[i])) {
                    return extSdPaths[i];
                }
            }
        }
        catch (IOException e) {
            return null;
        }
        return null;
    }

I am trying to get a better way to fix it...

arpitkh96 commented 9 years ago

Thats not a good way to do it.It will mess up with other devices.Still if you can compile ,you can try the latest commit

wuliou commented 9 years ago

Yup it's not a good way, that will make the app crash on my phone. So I didn't push it.

wuliou commented 9 years ago

I close the issue accidentally, sorry.

arpitkh96 commented 9 years ago

Try compiling with latest commits

wuliou commented 9 years ago

Sorry for late reply. I ran into compiling problem. I'm trying to solve it.

arpitkh96 commented 8 years ago

Reopen if you still have problem