I'm following along this thread, and calling saveFrames
MediaMetadataRetriever.getFrameAtTime() returns only first frame
He is saving in Environment.getExternalStorageDirectory()+ "/videos/frames/" . Which turns out to be "/storage/emulated/0" . When I click on device explorer and "/storage/emulated" it says "Permission denied". Is there a way to access this, or is there another place that I can store the data?
Update:
So here's how I solved it. I can cd to that /storage/emulated/0 using adb shell. However I cannot write to it. I change the directory name to
String folder = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/frame/" ;
I can see all the files there. To retrieve the files and view them, I use
adb pull /storage/emulated/0/Android/data/com.example.<app>/files/Pictures/frame
Here are more detailed discussions on storage permissions:
WRITE_EXTERNAL_STORAGE when targeting Android 10
Android Studio - How to use getExternalFilesDir
https://developer.android.com/training/data-storage/manage-all-files
https://support.google.com/googleplay/android-developer/answer/10467955
https://developer.android.com/training/data-storage
requestLegacyExternalStorage is not working in Android 11 - API 30
https://www.dev2qa.com/android-read-write-external-storage-file-example/
Related
My Android-APP creates text files that have to be read by other apps.
I originally chose the following directory, which no longer works:
Environment.getExternalStoragePublicDirectory((Environment.DIRECTORY_DOCUMENTS))
Right now I'm trying the directory:
getFilesDir()
The problem here is that no other app can access this folder.
I'm puzzled as I simply don't know which directory I can use for an exchange between apps.
I have some files you can say a trained model that I need to get their path in my activity class.
I want to use getFilesDir()but it return "data/user/0/com.example.abc/files/".
I just don't know which folder or directory I have to paste my files exactly in order to be in this path so that these file can be get through getFilesDir().
This is the folder on your device
You can find it by opening "Device File Explorer" (this is a collapsed tab in the bottom right of your Android Studio - written vertically on the right edge, bottom)
There you open the folders data/data/com.yourpackage.name/files
Upload your files to this folder and your app can pick them up.
Hope this helps.
Use this way only to test things. For a production scenario you need to package your files in the project, like in the raw or assets folders of your app's resources, so they are contained in the .apk or .aab app bundle.
You can not access this folder via Windows Explorer. The Device must be in developer mode and adb must be running, so you can only access it through android studio or adb command shell. Keep that in mind.
I'm trying to download an APK file online from within my app and then install it using Java. My code basically, downloads the file to the device from my server and then uses an Intent to open the installation message from the package manager and allow the app to be installed.
It works perfectly for me... unless I save the file to cache instead of regular storage. If I save it to cache instead, I get an error that it could not parse the APK file.
I checked and it is downloading the entire file to the cache correctly, but it just not installing. Any ideas?
The only difference in my code is that instead of using Environment.getExternalStorageDirectory() + "/file.apk" I'm trying to use context.getCacheDir() + "/file.apk" as for my file path.
I want to put the file in the cache so that Android can handle the cleaning of the file and so that I don't need to worry about handling write permissions on different Android versions and the variations of dealing with external storage.
I created a simple file write/read app in Eclipse and have successfully tested that it could read what it wrote. The structure is fairly simple. I use FileOutputStream to write a samplefile.txt using openFileOutput and a FileInputStream using openFileInput to read it back. The only minor thing is that I don't know where is the file on my physical hard drive? Can anybody point me to where I could find the file in Windows?
If you dont give a absolute path the file will be creataed in aplication directory.
This is /data/data/packge-name-of-your-app/
e.g:
/data/data/com.example.test/
See more http://developer.android.com/training/basics/data-storage/files.html
Go to DDMS perspective, select the emulator which you are using, go to package explorer tag ,then you will get a list of folders hierarchy.
Go to /data/data/
Now you will see a list of packages installed, search for the package name of your app and expand it.
Here you will see the files which your application created when it was running.
P.S : You cannot find this file on the physical drive of your computer,because it is present in the storage of the emulated android virtual device. This storage cannot be directly accessed by you.
Unable to create a new directory in Android external storage for some reason, Im assuming there is something im missing but not able to spot it below is my code which I am using to attempt to create the directory, any help will go a long way thanks
Calendar calendarTime = Calendar.getInstance();
String newFolder = "/NewFolder/videos";
File newDirectory = new File(Environment
.getExternalStorageDirectory().toString() + newFolder);
newDirectory.mkdir();
File file = new File(newDirectory,
String.valueOf(calendarTime.getTimeInMillis()) + ".mp4");
if (camcorderProfile.fileFormat == MediaRecorder.OutputFormat.THREE_GPP) {
recorder.setOutputFile(file.getAbsolutePath());
} else if (camcorderProfile.fileFormat == MediaRecorder.OutputFormat.MPEG_4) {
recorder.setOutputFile(file.getAbsolutePath());
} else {
recorder.setOutputFile(file.getAbsolutePath());
}
and in my manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
File.mkdir() will only create the directory if its parent exists. In this case, the directory you want to create is "videos" and its parent is "NewFolder". "videos" will not be created if "NewFolder" does not exist. If you want to create both directories at once, you should use File.mkdirs() instead.
I was stuck with issue of folder not getting created for 2 days. Code was perfect, tried multiple code options but none worked. Ultimately I rebooted by device - Nexus 4 and reconnected to my Windows 7 laptop for debugging. I was able to see all files and the directory in Windows 7 explorer. Looks like it was just issue with Nexus 4 (kitkat) not refreshing the folder structure and it was also not visible on Windows 7 explorer and was not working with my app.
Also after restart of Nexus 4 the error from call mediaRecorder.start() "not able to start" also disappeared and all files and directories my app is creating appeared.
Do not forget to ask for WRITE_EXTERNAL_STORAGE permission explicitly.
Here is how to do that: https://developer.android.com/training/permissions/requesting