I am trying to get access to a text file (log.txt) in a directory. All other questions on this topic refer to getting directories from the emulators internal storage.
My file structure is as such
>androidApp
->App
-->Build
-->src
--->game_log
---->log.txt
--->Main
---->(Android app Code further)
Using new File(System.getProperty("user.dir) + "app\\src\\game_log\\log.txt").exists() gets me false.
Another thing I tried was System.getProperty("user.dir") but that yields me /.
Contextwrapper.getPath() gets me the path of the emulators storage.
Is the file structure of Android Studio different or I am using the wrong method to get the file from my project folder?
Related
I want to get all files from WhatsApp's .Statuses folder. Until Android 10 im perfectly getting all statuses files. But on Android 11 due to new restrictions, when I code like below:
File(Environment.getExternalStorageDirectory().absolutePath + File.separator + "Android/media/com.whatsapp/WhatsApp/Media/.Statuses").listFiles()
I always get 0 files. Whereas, Im successfully getting other folder files "Android/media/com.whatsapp/WhatsApp/Media/" on this path.
Two problems I'm facing now:
If a folder is hidden then in Android 11, listFiles() returns 0 on that folder.
If a folder not hidden but contains one file as ".nomedia" , listFiles() returns 0 on that folder as well in Android 11.
What should I do to get all whatsapp statuses files in Android 11?
I dont want to use MANAGE_EXTERNAL_STORAGE permission for it due to google policies. Thank you
There are ways to access Hidden Directory in Android 11, two of them are:
Storage access framework (SAF) in which you take user to that specific directory and ask for permission from user to access directory files and that way you get access to files in it (Study SAF).
You can use File Observer on that hidden folder and whenever any file created or modified or deleted from that hidden directory you will get full path in that case for that specific file in hidden folder & once you have full path you can have access to that file.
I have read online that to make a directory in the internal storage we use the following line of code
File dir = getDir("mydir", Context.MODE_PRIVATE);
however, when I execute this code along with my entire source code, I can't seem to find the directory I created in my phone. Isn't it supposed to be saved into the android/data directory where all other apps data is stored? I am slightly confused.
private file stored in
/data/data/<packagename>/files
I am trying to figure out how to get the name of the original .apk file from which an application was installed. I know that you can retrieve the package name and the source directory of the installed application by using the ApplicationInfo class (described here: Android: how to get the name of apk file programmatically?) but this is NOT what I want.
As an example, suppose I have a simple application that is named TestApp (via the android:label tag in the AndroidManifest.xml file). Furthermore, suppose I generate an .apk file for the application above, rename said .apk file to TestApp_JohnDoe.apk, and then email that application to John Doe for installation. When John Doe installs the application by clicking on the .apk file I would like to be able to read the filename of the original .apk, TestApp_JohnDoe.apk, that I sent to him. Using the ApplicationInfo class, more specifically the sourceDir method gives me the install directory and application name, /data/app/TestApp.apk, which is not what I am looking for. I know that it is probably possible to scan all available directories looking for the original .apk file, but I am hoping to avoid this.
In summary, I would like to programatically retrieve the .apk filename/source directory of the installer .apk, such as /storage/sdcard0/Download/TestApp_JohnDoe.apk, as opposed to the .apk filename/source directory of the actual installed application, /data/app/TestApp.apk.
It is possible to let the app know the apk name that was set at compile time, if that is of any use to you
applicationVariants.all { variant ->
// Change the target apk file name and path
String apk_path = "$rootProject.projectDir/bin"
String apk_name = "john_doe.apk"
project.delete(project.apk_path) //Delete any remains
String apkFile = String.format("%s/%s", apk_path, apk_name)
variant.outputs[0].outputFile = new File(apkFile)
// This can be used in Java runtime by using getString(R.string.apk_name)
resValue "string", "apk_name", apk_name
}
But what you are asking, I am pretty sure it is not possible
I have created an app using javaCv and
I'm trying to save an image in android using
cvSaveImage("/storage/sdcard0/watermarked/test.jpg", yCrCb);
cvSaveImage("/storage/extSdCard/test.jpg",yCrCb);
where yCrCb is an IplImage.
There is no exception error and the program runs smoothly but the files are not saved into the path as mentioned above.
I would like to ask what might be the possible problems ? is it the naming convention of the file name ?
If it helps, I have a java application counterpart of this app and the java version works fine when i use the line
cvSaveImage("C:\\testing123.jpg", yCrCb);
Hi I have used same thing for storing the image.
For getting the path to sdcard, I have used the Environment.getExternalStorageDirectory().toString();
append the folder name to this path where you want to store the image
try this and also make sure that you have written permission in the xml file.
I am looking for an appropriate way to store and access pdf files in my Android app.
The problem is: I have 5 pdf-files which I would like to store in the project resources and load in the app.
I have tried to make a new directory in the project root /myApp/pdfs, and accessing it by:
File myFile = new File("/myApp/pdfs/,fileName);
I have tried some different variants of the path name: ./myApp/pdfs, myApp/pdfs, /pdfs, ./pdfs. However I get the same message stating that the file can't be found.
How do I get the path to my apps directory? And is this the most appropriate approach for saving a small number of pdf-files?
If you are wanting to load the pdfs from the app (while the app is running), you probably want to store them in the res/raw folder.