問題

為什麼這段程式碼是我的白線繪圖問題,問題是什麼 有沒有辦法替換它?

 File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
 

這行程式碼是用白線方法繪製的 getExternalStoragePublicDirectory

  最佳答案

getExternalStoragePublicDirectory() – > Deprecated in API 級別29

為了改善使用者隱私,直接訪問共享/外部儲存 裝置被棄用.當應用程式針對Build.VERSION_CODES.Q時, 從此方法返回的路徑不再直接訪問 應用程式.應用程式可以繼續訪問儲存在共享/外部的內容 遷移到替代品,例如 Context#getExternalFilesDir(String) ,MediaStore,或 意圖#ACTION_OPEN_DOCUMENT。

 void createExternalStoragePrivateFile() {
    // Create a path where we will place our private file on external
    // storage.
    File file = new File(getExternalFilesDir(null), "DemoFile.jpg");

    try {
        // Very simple code to copy a picture from the application's
        // resource into the external file.  Note that this code does
        // no error checking, and assumes the picture is small (does not
        // try to copy it in chunks).  Note that if external storage is
        // not currently mounted this will silently fail.
        InputStream is = getResources().openRawResource(R.drawable.balloons);
        OutputStream os = new FileOutputStream(file);
        byte[] data = new byte[is.available()];
        is.read(data);
        os.write(data);
        is.close();
        os.close();
    } catch (IOException e) {
        // Unable to create file, likely because external storage is
        // not currently mounted.
        Log.w("ExternalStorage", "Error writing " + file, e);
    }
}
 

  相同標籤的其他問題

androidpathfilepath