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>

  • 相关阅读:
    VS2019 .Net Core 3.1 Web 项目启用动态编译
    IntelliJ IDEA自动注释作者信息和日期时间
    Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.1.RELEASE from/to
    MS SQL Server数据批量插入优化详细
    更改VisualStudio默认创建类和接口不加public问题
    WIN10 报错 "此共享需要过时的SMB1协议,而此协议是不安全"的解决方法
    Delphi XE8,C++ Builder XE8,RAD Studio XE8 官方 ISO 文件下载,附激活工具
    PC 安装MAC
    InnoSetup能够实现“安装细节描述”界面吗?
    在Unicode版Inno Setup中使用ISSkin
  • 原文地址:https://www.cnblogs.com/alimjan/p/7120278.html
Copyright © 2011-2022 走看看