2023年3月7日 星期二

Android Studio - Android 12 內部存儲空間路徑程式(一百零六)

Android Studio - Android 12 內部存儲空間路徑程式(一百零六):

筆者將 Android 12 內部存儲空間(Internal Storage)的路徑放入程式內作測試,內部存儲空間路徑也是蠻多,所以將資料匯集紀錄,因為很多時候需要讀寫本地檔的操作,將來作參考作用。

Android 12 內部存儲空間路徑程式
操作系統:Windows 7 64-bit 版本
開發環境:Android Studio 4.0.1 版本
最低 SDK 版本:minSdkVersion 24
測試手機:Samsung Galaxy M33 5G
測試手機系統版本:Android 12(Snow Cone / 2021)
原程式:C:\Development\Development_Android\DIY-Android-190-15d Android12ReadWriteFile bugworkshop 20230304 - ReadWriteFileStorage
程式:C:\Development\Development_Android\Android_Project\DIY-Android-190-15d Android12ReadWriteFile bugworkshop 20230304 - ReadWriteFileStorage

MainActivity.java - internalStorage:

    public void internalStorage(){

 

        String PackageName = getPackageName();

        Log.d(MainActivity.TAG, "ReadWriteFileInt.internalStorage().getPackageName=" + PackageName );

 

        // File

        File getFilesDir = new File(getFilesDir(), "fileName");

        File getCacheDir = new File(getCacheDir(), "fileName");

        File getFileStreamPath = new File(getFileStreamPath("Stream"), "fileName");

        File getDatabasePath = new File(getDatabasePath("Datbase"), "fileName");

        File getObbDir = new File(getObbDir(), "fileName");

        File getDir = new File(getDir("Dir", 0), "fileName");

        File getCodeCacheDir = new File(getCodeCacheDir(), "fileName"); // API21

        File getNoBackupFilesDir = new File(getNoBackupFilesDir(), "fileName"); // API21

        File getDataDir = new File(getDataDir(), "fileName"); // API24

 

        // String

        String rootDirectory = Environment.getRootDirectory().getPath();

        String dataDirectory = Environment.getDataDirectory().getPath();

        String downloadCacheDirectory = Environment.getDownloadCacheDirectory().getPath();

 

        // String

        String dcimDirectory = Environment.DIRECTORY_DCIM;

        String musicDirectory = Environment.DIRECTORY_MUSIC;

        String podcastsDirectory = Environment.DIRECTORY_PODCASTS;

        String ringtonesDirectory = Environment.DIRECTORY_RINGTONES;

        String alarmDirectory = Environment.DIRECTORY_ALARMS;

        String notificationDirectory = Environment.DIRECTORY_NOTIFICATIONS;

        String picturesDirectory = Environment.DIRECTORY_PICTURES;

        String moviesDirectory = Environment.DIRECTORY_MOVIES;

        String downloadsDirectory = Environment.DIRECTORY_DOWNLOADS;

        String documentsDirectory = Environment.DIRECTORY_DOCUMENTS;

 

        String content = "";

        // File

        content = content + "getCacheDir=" + getCacheDir + "\n";

        content = content + "getFileStreamPath=" + getFileStreamPath  + "\n";

        content = content + "getDatabasePath=" + getDatabasePath  + "\n";

        content = content + "getObbDir=" + getObbDir  + "\n";

        content = content + "getDir=" + getDir  + "\n";

        content = content + "getCodeCacheDir=" + getCodeCacheDir  + "\n"; // API21

        content = content + "getNoBackupFilesDir=" + getNoBackupFilesDir  + "\n"; // API21

        content = content + "getDataDir=" + getDataDir  + "\n"; // API24

        content = content + "Environment.getRootDirectory().getPath()=" + rootDirectory  + "\n";

        content = content + "Environment.getDataDirectory().getPath()=" + dataDirectory  + "\n";

        content = content + "Environment.getDownloadCacheDirectory().getPath()=" + downloadCacheDirectory  + "\n";

 

        // String

        content = content + "Environment.DIRECTORY_DCIM=" + dcimDirectory  + "\n";

        content = content + "Environment.DIRECTORY_MUSIC=" + musicDirectory  + "\n";

        content = content + "Environment.DIRECTORY_PODCASTS=" + podcastsDirectory  + "\n";

        content = content + "Environment.DIRECTORY_RINGTONES=" + ringtonesDirectory  + "\n";

        content = content + "Environment.DIRECTORY_ALARMS=" + alarmDirectory  + "\n";

        content = content + "Environment.DIRECTORY_NOTIFICATIONS=" + notificationDirectory  + "\n";

        content = content + "Environment.DIRECTORY_PICTURES=" + picturesDirectory  + "\n";

        content = content + "Environment.DIRECTORY_MOVIES=" + moviesDirectory  + "\n";

        content = content + "Environment.DIRECTORY_DOWNLOADS=" + downloadsDirectory  + "\n";

        content = content + "Environment.DIRECTORY_DOCUMENTS=" + documentsDirectory  + "\n";

 

        mtxt_filecontent.setText(content);

    }



2023年 3月 7日(Tue)天氣報告
氣溫:37.0°F / 3.0°C @ 07:00
風速:每小時 2公里
降雨機會:9%
相對濕度:百分之 88%
天氣:多雲時陰

沒有留言:

張貼留言