I want to access Chrome browser directory in android/data and then copy files(TXT) From assets to that folder
1.how to get permission In Android 11
2.after getting permission How to copy any file from asset folder to that directory
Please give me an code that works like this
Image First
Image Second
App link above screenshot: https://play.google.com/store/apps/details?id=eu.tsoml.graphicssettings
If your app holds REQUEST_INSTALL_PACKAGES permission it can access Android/obb directory.
and for more details
Related
Can and Android service running in background create directory in external storage public directory. If yes how to do it please share sample code.
However I am getting permission denied even after adding permit in manifest file
On Android 10 and above, have a look at the scope storage feature.
Source:- https://developer.android.com/training/data-storage
I made an APK with the help of KivyApp. APK generated successfully and my APK also runs on my mobile. The problem is that I didn't give any specific path for the CSV file, which stored the output generated by the app. Initially, I run python code in the pydroid3 app and it automatically generated the CSV file at the same location, where my code was stored. My question is if I want to store the data in the internal storage of my mobile, what path should I enter?
import csv
csvfile = "Discrete_pos.csv"
with open(csvfile, "a") as fp:
wr = csv.writer(fp, dialect='excel')
wr.writerow(csvRow)
Well, I suppose you mean the path of External Storage (which can be accessed by any app, one you see in your mobile file explorer) As it's already storing in your internal storage path. Now to access external storage there are 2 methods. But first of all you need storage permission for that. To get storage permission use the following code:
from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE])
Now after you have access to external storage you can use the following code to get external storage path:
from android.storage import primary_external_storage_path
external_storage = primary_external_storage_path()
Sometimes this doesn't work on some android devices so if you are getting that issue then you can also use os.getenv:
external_storage = os.getenv('EXTERNAL_STORAGE')
Also, don't forget to write READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE in the permissions of your buildozer.spec file
I try to access the file I had downloaded from flutter app and save it to external storage. I call the file and use it in java part but it show this error:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/abc.xyz.qwe/files/mobilenet.tflite
I have tried to grant permission before call the file but it still not work (The file is exist, i have checked).
You start the file name with a slash. What directory is the file located in? If the storage folder is not in the root directory (/), then you won't be able to find the file. If storage is in the same place as the java file you're running, you should remove the first /
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
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.
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";
Im trying to create a sqlLite db. This code works and create the db and allow me do insert and select.
string dbPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
"ormdemo.db3");
//dbPath = "/storage/emulated/0/DCIM/ormdemo.db3";
var db = new SQLiteConnection(dbPath);
db.CreateTable<Stock>();
Right now the dbPath returned is:
"/data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3"
But when I use a sqlLite Manager to try open the db I cant find the folder /data/user
Where is that folder /data/user?
The sqlLite have the option to open "APP" databases, but when try to select MyFirstGPSApp say need a root device.
The starting folder for sqlLite is /storage/emulated/0 and have a sub folder /DCIM
So I try to use a folder I can see ... like /storage/emulated/0/DCIM/ormdemo.db3 but then the new SQLiteConnection(dbPath) give me this error.
SQLite.SQLiteException: Could not open database file: /storage/emulated/0/DCIM/ormdemo.db3 (CannotOpen)
Do I need special permision to write in /DCIM folder?
Ok, there are three questions in your post. Before answer your questions, I think some pictures are necessary.
P1:
P2:
Like #Yogesh Paliyal has said, you need File Explorer to see it. If you also want to see it and you don't want to root you device, please follow me: Visual Studio->Tools->Android->Android Device Monitor->select one simulator from Devices column->File Explorer. I suggest you create a simulator which Api is below 21, because the higher also can't see the file. I am using 19 to see the files.
And I think you should read this firstly.
Ok, let's see your questions:
Where is the app Personal Folder path?
In android, there are two folder: personal/internal folder and public/external folder, here is official document.
Personal/Internal Folder path:
/data/data/package name/shared_prefs: SharedPreferences
/data/data/package name/databases: Sqlite
/data/data/package name/files: Api:getFilesDir()
/data/data/package name/cache: Api:getCacheDir()
/storage/sdcard/Android/data/package name/files: Api:getExternalFilesDir()
/storage/sdcard/Android/data/package name/cache: Api:getExternalCacheDir()
Public/External Folder path:
In /storage/sdcard folder, only Android folder is personal/internal folder,so /storage/sdcard/DCIM, /storage/sdcard/Music,etc, all of them are public/external folder: Api:Environment.getExternalStoragePublicDirectory(String type)
Where is that folder /data/user?
From P1, you can see the ->/data/data/ is behind of /data/user/0, so the folder /data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3 is /data/data/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3 actually.
Do I need special permision to write in /DCIM folder?
Personal/Internal folder doesn't need permission, public/external folder need permission.
In /storage/sdcard folder, only Android folder is personal/internal folder, so you need permission:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> or <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> or both.
You can't see directly from mobile without root permissions.
Try using Android Studio's File explorer feature.