Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

数据存储——四种存储方式——存储卡的文件操作——私有存储空间与公共存储空间

 Share


Recommended Posts

1895087-20220710174213151-1079774400.png

 

 

 

 

 

 

1895087-20220710175918433-346886476.png

 

 

 

 

 

==============================================================================

 

 

 

 

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp" >

    <TextView
        android:id="@+id/tv_path"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:textSize="17sp" />

</LinearLayout>

1895087-20220710174911034-1774313278.png

 

 

 

 

 

 

 

 

 

 

package com.example.myapplication;

import android.os.Build;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv_path = findViewById(R.id.tv_path);

        // Android7.0之后默认禁止访问公共存储目录
        // 获取系统的公共存储路径
        String publicPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();

        // 获取当前App的私有存储路径
        String privatePath = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString();

        boolean isLegacy = true;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
        {
            // Android10的存储空间默认采取分区方式,此处判断是传统方式还是分区方式
            isLegacy = Environment.isExternalStorageLegacy();
        }

        String desc = "系统的公共存储路径位于" + publicPath +
                "\n\n当前App的私有存储路径位于" + privatePath +
                "\n\nAndroid7.0之后默认禁止访问公共存储目录" +
                "\n\n当前App的存储空间采取" + (isLegacy?"传统方式":"分区方式");

        tv_path.setText(desc);
    }
}

1895087-20220710174950757-538452481.png

 

 

 

 

 

 

 

 

 

 

小米手机:

1895087-20220710175058138-2146105252.png

 

 

 

 

 

 

 

 

 

 

荣耀手机:

 

1895087-20220710175248375-809962986.png

 

 

 

 

 

 

 

 

 

 

 

=============================================================================

 

 

 

 

 

 

 

<!-- 存储卡读写 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


<!-- Android10新增权限MANAGE_EXTERNAL_STORAGE -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

 

 

 

1895087-20220710175757927-1047055616.png

 

 1895087-20220710175835387-1481502229.png

 

 1895087-20220710175851192-1488680947.png

 

 1895087-20220710175905096-650598712.png

 

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...