Android SD卡
发布日期:2021-05-10 11:49:34 浏览次数:12 分类:精选文章

本文共 3491 字,大约阅读时间需要 11 分钟。

������������SD���������������

���Android������������������������������������������������������������������SD������������mount������������������������������������ ```java if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(MainActivity.this, "SD���������������", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "SD���������������������������", Toast.LENGTH_SHORT).show(); } ```

������������SD������������������������

������������SD������������������������������������������������������������������������������ ```java File extStorage = Environment.getExternalStorageDirectory(); long usableSpace = extStorage.getUsableSpace(); long totalSpace = extStorage.getTotalSpace(); String usableSize = Formatter.formatFileSize(MainActivity.this, usableSpace); String totalSize = Formatter.formatFileSize(MainActivity.this, totalSpace); Toast.makeText(MainActivity.this, "���������������" + usableSize + "���������������" + totalSize, Toast.LENGTH_SHORT).show(); ```

������Android������������

���Android6.0���API level 23���������������������������������������������������������������������������������Canonical��������������������������������� ```xml
```

���������������������������������������������������

private static final int REQUEST_EXTERNAL_STORAGE = 1;  private static String[] PERMISSIONS_STORAGE = {      "android.permission.READ_EXTERNAL_STORAGE",      "android.permission.WRITE_EXTERNAL_STORAGE"  };  public static void verifyStoragePermissions(Activity activity) {      try {          int permission = ActivityCompat.checkSelfPermission(activity, "android.permission.WRITE_EXTERNAL_STORAGE");          if (permission != PackageManager.PERMISSION_GRANTED) {              ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);          }      } catch (Exception e) {          e.printStackTrace();      }  }

������������SD���������

���������������������������������������������SD������������������������������������������������������������������������ ```java File file = new File(extStorage, "test.txt"); try { verifyStoragePermissions(MainActivity.this); OutputStream out = new FileOutputStream(file); out.write("������������������������!".getBytes()); out.close(); } catch (Exception e) { e.printStackTrace(); } ```

������������������������������������

File file = new File(extStorage, "test.txt");  try {      InputStream in = new FileInputStream(file);      byte[] buffer = new byte[64];      int len = in.read(buffer);      String content = new String(buffer, 0, len);      Toast.makeText(MainActivity.this, "���������������" + content, Toast.LENGTH_SHORT).show();  } catch (Exception e) {      e.printStackTrace();  }

���������������������������

������������������������������������������������������shell���������������������������������������������������`cp`��������������������� ```bash sudo cp /path/to/source /mnt/external/destination/ ``` ���������������������������������������`tr`���`awk`��������������������������������������������������� ```bash find /mnt/external/ -name "*.log" -type f -exec mv -t /mnt/backup/ {} \; ```

������������������������

������������������������������������������������������������������ 1. ������shell������������������������������������������ 2. ������������������������������������������������������ 3. ������������������������������������������������������������ 4. ���������Comparator���Collection������������������������������������������
上一篇:Android SharedPreferences
下一篇:转译字符

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月20日 23时11分36秒