Android Environment 获取各种路径的方法

package com.deepoon.beyond.environment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;

import com.deepoon.beyond.R;

public class EnvironmentActivity extends Activity {
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_environment);
        TextView textViewDataDirectory = (TextView) findViewById(R.id.textview_data_directory);
        textViewDataDirectory.setText(Environment.getDataDirectory().getPath());

        TextView textViewRootDirectory = (TextView) findViewById(R.id.textview_root_directory);
        textViewRootDirectory.setText(Environment.getRootDirectory().getPath());

        TextView textViewExternalStorageState = (TextView) findViewById(R.id.textview_external_storage_state);
        textViewExternalStorageState.setText(Environment.getExternalStorageState().toString());

        TextView textViewDownloadCacheDirectory = (TextView) findViewById(R.id.textview_download_cache_directory);
        textViewDownloadCacheDirectory.setText(Environment.getDownloadCacheDirectory().getPath());

        TextView textViewExternalStorageDirectory = (TextView) findViewById(R.id.textview_external_storage_directory);
        textViewExternalStorageDirectory.setText(Environment.getExternalStorageDirectory().getPath());

        TextView textViewExternalStorageEmulated = (TextView) findViewById(R.id.textview_external_storage_emulated);
        textViewExternalStorageEmulated.setText("设备的外存是否是用内存模拟的: " + Environment.isExternalStorageEmulated());

        TextView textViewExternalStorageRemovable = (TextView) findViewById(R.id.textview_external_storage_removable);
        textViewExternalStorageRemovable.setText("设备的外存是否是可以拆卸的: " + Environment.isExternalStorageRemovable());

        TextView textViewDirectoryAlarms = (TextView) findViewById(R.id.textview_directory_alarms);
        textViewDirectoryAlarms.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS).getPath());

        TextView textViewDirectoryDCIM = (TextView) findViewById(R.id.textview_directory_dcim);
        textViewDirectoryDCIM.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath());

        TextView textViewDirectoryDocuments = (TextView) findViewById(R.id.textview_directory_documents);
        textViewDirectoryDocuments.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getPath());

        TextView textViewDirectoryDownloads = (TextView) findViewById(R.id.textview_directory_downloads);
        textViewDirectoryDownloads.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath());

        TextView textViewDirectoryMovies = (TextView) findViewById(R.id.textview_directory_movies);
        textViewDirectoryMovies.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getPath());

        TextView textViewDirectoryMusic = (TextView) findViewById(R.id.textview_directory_music);
        textViewDirectoryMusic.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getPath());

        TextView textViewDirectoryNotifications = (TextView) findViewById(R.id.textview_directory_notifications);
        textViewDirectoryNotifications.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS).getPath());

        TextView textViewDirectoryPictures = (TextView) findViewById(R.id.textview_directory_pictures);
        textViewDirectoryPictures.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath());

        TextView textViewDirectoryPodcasts = (TextView) findViewById(R.id.textview_directory_podcasts);
        textViewDirectoryPodcasts.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS).getPath());

        TextView textViewDirectoryRingtones = (TextView) findViewById(R.id.textview_directory_ringtones);
        textViewDirectoryRingtones.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getPath());

        TextView textViewFilesDir = (TextView) findViewById(R.id.textview_files_dir);
        textViewFilesDir.setText(mContext.getFilesDir().getPath());

        TextView textViewCacheDir = (TextView) findViewById(R.id.textview_cache_dir);
        textViewCacheDir.setText(mContext.getCacheDir().getPath());

        TextView textViewExternalFilesDir = (TextView) findViewById(R.id.textview_external_files_dir);
        textViewExternalFilesDir.setText(mContext.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getPath());

        TextView textViewExternalCacheDir = (TextView) findViewById(R.id.textview_external_cache_dir);
        textViewExternalCacheDir.setText(mContext.getExternalCacheDir().getPath());

    }
}



    

        

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            

            
        
    
 
  

Android Environment 获取各种路径的方法_第1张图片

Android Environment 获取各种路径的方法_第2张图片

你可能感兴趣的:(Android应用开发,environment,getFilesDir,getCacheDir)