Android Tutorials - Herong's Tutorial Examples - v3.05, by Herong Yang
android.os.Environment Class - Environment Folders
This section provides tutorial example on how to display environment folders: data, external storage, download cache, and root folders using the android.os.Environment class.
Another Android class, android.os.Environment, can also be used to retrieve environment folder information as shown in the following example:
/* AboutAndroid.java * Version 5.0 - Adding environment folders * Copyright (c) 2015, HerongYang.com, All Rights Reserved. */ package com.herongyang; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.widget.ScrollView; import android.os.Environment; public class AboutAndroid extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String msg = ""; msg += "System properties\n"; msg += "-------------\n"; java.util.Properties props = System.getProperties(); java.util.Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { String k = (String) e.nextElement(); String v = props.getProperty(k); msg += k+": "+v+"\n"; } msg += "\n"; msg += "Environment variables\n"; msg += "-------------\n"; java.util.Map envs = System.getenv(); java.util.Set keys = envs.keySet(); java.util.Iterator i = keys.iterator(); while (i.hasNext()) { String k = (String) i.next(); String v = (String) envs.get(k); msg += k+": "+v+"\n"; } msg += "\n"; msg += "Environment folders\n"; msg += "-------------\n"; msg += "Data folder: " +Environment.getDataDirectory().getPath()+"\n"; msg += "Download cache folder: " +Environment.getDownloadCacheDirectory().getPath()+"\n"; msg += "External Storage folder: " +Environment.getExternalStorageDirectory().getPath()+"\n"; msg += "Root folder: " +Environment.getRootDirectory().getPath()+"\n"; TextView tv = new TextView(this); tv.setText(msg); ScrollView sv = new ScrollView(this); sv.addView(tv); setContentView(sv); } }
2. Uninstall the previous version, build, install and run this new version. I get the following extra information at the end:
Data folder: /data Download cache folder: /cache External storage folder: /storage/sdcard Root folder: /system
Below was some system properties I got from my Android 4.0.3 emulator created with Android SDK R17:
Data folder: /data Download cache folder: /cache External storage folder: /mnt/sdcard Root folder: /system
Table of Contents
Installing JDK 1.8 on Windows System
Installation of Android SDK R24 and Emulator
Installing Apache Ant 1.9 on Windows System
Developing First Android Application - HelloAndroid
Android Application Package (APK) Files
Android Debug Bridge (adb) Tool
►AboutAndroid - Application to Retrieve System Information
java.lang.System Class - Accessing System Information
Creating Android Project for Simple Application
Build, Install and Run Android Application
System.getProperties() - Retrieving System Properties
android.widget.ScrollView Class - Scrolling Text View
System.getenv() Method - System Environment Variables
►android.os.Environment Class - Environment Folders
android.content.Context - Application Context Information
android.app.Activity Class and Activity Lifecycle
View Objects and Layout Resource Files
Using "adb logcat" Command for Debugging
Build Process and Package File Content
Samsung Galaxy Tab 3 Mini Tablet
USB Debugging Applications on Samsung Tablet
USB Debugging Applications on LG-V905R Tablet