Note that there are some explanatory texts on larger screens.

plurals
  1. PORead file from "extsdcard"
    primarykey
    data
    text
    <p>I have some music in both sdcard and extsdcard</p> <p>I use Cursor to list them:</p> <pre><code>Uri deviceMusic = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; String sortOrder = MediaStore.Audio.Media.DISPLAY_NAME; Cursor cursor = this.getContentResolver().query(deviceMusic, null, selection, null, sortOrder); if (cursor == null || cursor.isClosed()) { return; } // Get music information if (cursor.moveToFirst()) { // File path String data = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.DATA)); } while (cursor.moveToNext()); </code></pre> <p>then i use the code below to judge the type of music:</p> <pre><code>public static String getFileHeader(String filePath) { FileInputStream is = null; String value = null; try { is = new FileInputStream(filePath); byte[] b = new byte[3]; is.read(b, 0, b.length); value = bytesToHexString(b); } catch (Exception e) { e.printStackTrace(); } finally { if (null != is) { try { is.close(); } catch (IOException e) { } } } return value; } </code></pre> <p>this method works fine on sdcard, </p> <p>but encounter "FileNotFoundException" on extsdcard</p> <p>so i try to check the file with hard code:</p> <pre><code>File file = new File( "/storage/extSdCard/(I Can't Help) Falling In Love With You - UB 40.mp3"); if (file.exists()) { Log.i("", ""); } </code></pre> <p>it returns false when the above code in the loop of</p> <pre><code>while (cursor.moveToNext()) </code></pre> <p>but when i hard code in other place such as onCreate</p> <p>it return true...</p> <p>what's that situation?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload