After install app, Internal storage (Android>data) package folder not created
Asked Answered
F

2

6

When I fresh install app, I notice most of the app will have a folder created in Internal Storage > Android > Data > com.example.package folder. For example its facebook app it will be something like com.facebook.xxxxx.

However, one of the project I involve recently, I notice there is no such app folder in the path Internal storage > Android > Data > (No packege folder).

In what scenario it won't create an app folder in the above path ? Because most of the app I debug run via android studio or install via apk file...Always have one app folder in the above location by default.

Because I want to write below file into getFilesDir(),

File file = new File(activity.getFilesDir(),imageFileName);

By using getFilesDir(), written file will go into Android > Data > Package folder > Files folder, most of the installed app have a package folder path in Android > Data > (Here). Today I realise one of the project I am doing now, it doesn't create such package folder. So, when I use getFilesDir() , those files will still be stored and created inside the mentioned path but it is invisible? Or Those files I create using getFilesDir() won't be created? Because as I mentioned this app doesn't create a package folder. Do I have to use makedir ? If yes what will be the checking ? if(!activity.getFilesDir(). exist())

File file = new File(activity.getFilesDir(),imageFileName);

//getFilesDir() normally is package folder Android > Data > (package folder*) > Files
Frantz answered 15/4, 2019 at 10:7 Comment(2)
Please check is you can access activity.getCacheFir().Mithras
Hi Ajay, thanks for your reply. I'm not asking how to check if the file path directory is exist or how to create a folder in a specific path. My question is those package folder in storage > Android > Data, what scenario they won't be created ? Because most of the app I installed, there will be an empty folder named com.xxx.example but some app won't have it. This folder is package folder, by using getFilesDir() way to store file, it will go to storage > Android > Data > Package folder > Files. But what will happen if package folder by default didn't exist ? Shouldn't all app have it ?Frantz
F
3

I have tested and find out that if phone is having internal storage only (Not support SDCard) or maybe phone support external storage but don't have SDCard insert. App folder in this path by default won't be created (Android > Data > [App folder]), until I called (getExternalFilesDir(null) , "Example1") check its exists() and makedirs() if it doesn't exist, finally the app folder is created with a folder Example1 in this path Android > App > com.xxxxx.myapp > files > Example1.

However, why some sample app I create I never call getExternalFilesDir(null) or any File writing storage path but by default I can find my sample app path in Android > App > [Here].

Some app folder won't be created by default but until getExternalFilesDir(null) check exist and mkdirs then it become exist and created. Some app folder will be created when app is installed by default. How Android determine if the Android > App > App folder should be created and visible or created and make it invisible??

It makes me confuse. Some app will create app folder, some app wont create it by default when app is installed. Let's assume both app never call any File path create method. Just a very sample app I run using latest Android Studio to test something, it created package folder. The big project app is using old gradle settings and almost 5 years ago, the app by default won't create package folder until I call File(getExternalFilesDir(null), Example1) check if it exists and it doesn't then mkDirs(), package folder become created and visible.

Frantz answered 16/4, 2019 at 2:59 Comment(0)
C
0

How SY MY told you need to check if phone is having internal storage only (Not support SDCard) or maybe phone support external storage but don't have SDCard insert. App folder in this path by default won't be created. And how he checked you shoud make if statement. So... you can paste this code in your project:

File file = new File(getExternalFilesDir(null),fileName);
            if (!file.exists()&&file.mkdirs()){
                File file1 = new File(getFilesDir(), fileName);
            }

fileName it is a String varable with txt foramt:

private String fileName = "list.txt";
Conduit answered 21/12, 2022 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.