How can I get the external SD card path for Android 4.0+?

前端 未结 26 3456
清歌不尽
清歌不尽 2020-11-22 04:48

Samsung Galaxy S3 has an external SD card slot, which is mounted to /mnt/extSdCard.

How can I get this path by something like Environment.getExter

26条回答
  •  我在风中等你
    2020-11-22 05:50

    I am sure this code will surely resolve your issues...This is working fine for me...\

    try {
                File mountFile = new File("/proc/mounts");
                usbFoundCount=0;
                sdcardFoundCount=0;
                if(mountFile.exists())
                 {
                    Scanner usbscanner = new Scanner(mountFile);
                    while (usbscanner.hasNext()) {
                        String line = usbscanner.nextLine();
                        if (line.startsWith("/dev/fuse /storage/usbcard1")) {
                            usbFoundCount=1;
                            Log.i("-----USB--------","USB Connected and properly mounted---/dev/fuse /storage/usbcard1" );
                        }
                }
             }
                if(mountFile.exists()){
                    Scanner sdcardscanner = new Scanner(mountFile);
                    while (sdcardscanner.hasNext()) {
                        String line = sdcardscanner.nextLine();
                        if (line.startsWith("/dev/fuse /storage/sdcard1")) {
                            sdcardFoundCount=1;
                            Log.i("-----USB--------","USB Connected and properly mounted---/dev/fuse /storage/sdcard1" );
                        }
                }
             }
                if(usbFoundCount==1)
                {
                    Toast.makeText(context,"USB Connected and properly mounted", 7000).show();
                    Log.i("-----USB--------","USB Connected and properly mounted" );
                }
                else
                {
                    Toast.makeText(context,"USB not found!!!!", 7000).show();
                    Log.i("-----USB--------","USB not found!!!!" );
    
                }
                if(sdcardFoundCount==1)
                {
                    Toast.makeText(context,"SDCard Connected and properly mounted", 7000).show();
                    Log.i("-----SDCard--------","SDCard Connected and properly mounted" );
                }
                else
                {
                    Toast.makeText(context,"SDCard not found!!!!", 7000).show();
                    Log.i("-----SDCard--------","SDCard not found!!!!" );
    
                }
            }catch (Exception e) {
                e.printStackTrace();
            } 
    

提交回复
热议问题