zoukankan      html  css  js  c++  java
  • Android 开发笔记___SD卡基本操作

     1 package com.example.alimjan.hello_world;
     2 
     3 /**
     4  * Created by alimjan on 7/5/2017.
     5  */
     6 
     7         import android.annotation.TargetApi;
     8         import android.content.Context;
     9         import android.content.Intent;
    10         import android.os.Build;
    11         import android.os.Build.VERSION;
    12         import android.os.Bundle;
    13         import android.os.Environment;
    14         import android.support.v7.app.AppCompatActivity;
    15         import android.widget.TextView;
    16 
    17 public class class__4_3_1 extends AppCompatActivity {
    18 
    19     private TextView tv_file_basic;
    20 
    21     @Override
    22     protected void onCreate(Bundle savedInstanceState) {
    23         super.onCreate(savedInstanceState);
    24         setContentView(R.layout.code_4_3_1);
    25         tv_file_basic = (TextView) findViewById(R.id.tv_file_basic);
    26         getEnvironmentInfo();
    27     }
    28 
    29     @TargetApi(Build.VERSION_CODES.KITKAT)
    30     private void getEnvironmentInfo() {
    31         String desc = "系统环境(含SD卡)的信息如下:";
    32         desc = String.format("%s
     根目录路径:%s", desc,
    33                 Environment.getRootDirectory().getAbsolutePath());
    34         desc = String.format("%s
     数据目录路径:%s", desc,
    35                 Environment.getDataDirectory().getAbsolutePath());
    36         desc = String.format("%s
     下载缓存目录路径:%s", desc,
    37                 Environment.getDownloadCacheDirectory().getAbsolutePath());
    38         desc = String.format("%s
     外部存储(即SD卡)目录路径:%s", desc,
    39                 Environment.getExternalStorageDirectory().getAbsolutePath());
    40         desc = String.format("%s
     外部存储(即SD卡)状态:%s", desc,
    41                 Environment.getExternalStorageState());
    42         desc = String.format("%s
     SD卡的相机目录路径:%s", desc,
    43                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
    44         //DIRECTORY_DOCUMENTS是Android4.4.2(SDK19)及以上版本才有的常量
    45         //如果不做SDK版本判断,那么在低版本Android(例如4.2.2)上运行会报错
    46         //java.lang.NoSuchFieldError: android.os.Environment.DIRECTORY_DOCUMENTS
    47         if (VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    48             desc = String.format("%s
     SD卡的文档目录路径:%s", desc,
    49                     Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));
    50         }
    51         desc = String.format("%s
     SD卡的下载目录路径:%s", desc,
    52                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    53         desc = String.format("%s
     SD卡的图片目录路径:%s", desc,
    54                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
    55         desc = String.format("%s
     SD卡的视频目录路径:%s", desc,
    56                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES));
    57         desc = String.format("%s
     SD卡的音乐目录路径:%s", desc,
    58                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC));
    59         tv_file_basic.setText(desc);
    60     }
    61 
    62     public static void startHome(Context mcontext){
    63         Intent intent = new Intent(mcontext,class__4_3_1.class);
    64         mcontext.startActivity(intent);
    65     }
    66 
    67 }
     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="match_parent"
     3     android:layout_height="match_parent"
     4     android:focusable="true"
     5     android:focusableInTouchMode="true"
     6     android:orientation="vertical"
     7     android:padding="10dp" >
     8 
     9     <TextView
    10         android:id="@+id/tv_file_basic"
    11         android:layout_width="match_parent"
    12         android:layout_height="wrap_content"
    13         android:textColor="@color/black"
    14         android:textSize="17sp" />
    15 
    16 </LinearLayout>

  • 相关阅读:
    深度学习:卷积神经网络(convolution neural network)
    Caffe使用step by step:r-cnn目标检测代码
    Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning
    Caffe使用step by step:caffe框架下的基本操作和分析
    (论文阅读)2015.10.8图像识别中的深度学习
    Caffe搭建:常见问题解决办法和ubuntu使用中遇到问题(持续更新)
    Ubuntu 14.04(64bit)使用indicator-sysmonitor显示系统运行状态
    SpringBoot配置文件自动映射到属性和实体类(8)
    SpringBoot热部署(7)
    SpringBoot之MultipartFile文件上传(6)
  • 原文地址:https://www.cnblogs.com/alimjan/p/7120278.html
Copyright © 2011-2022 走看看