Initial uri changes automatically in DOCUMENT_TREE,when where and why? - java

I am taking permission of scope storage through Intent with DOCUMENT_TREE, where, in intent we set initial uri to Android, media folder, and set functionality that if permission of that folder not granted, show again Permission fragment, where we ask again permission
but, at that time we click on button to open DOCUMENT_TREE Intent, it doesn't show Android/media folder directly, it shows another folder, which folder (eg we granted com.telegram folder) , then it shows telegram folder directly to grant permission.
so where is the problem, and how we can solve?? so it open only given uri folder every time??
so where is the problem, and how we can solve?? so it open only given uri folder every time??

Related

After taking permission of DOCUMENT_TREE,its real path shows access denied

I take DOCUMENT_TREE uri read permission, and i have to copy its video to other folder, so after all we find that if i can get actual path then i can copy that file to other Folder,some methods of get path shows Error No such directory, but finally a method shows access denied that folder.
so basically two question here generated
is READ_EXTERNAL_STORAGE have to use, to that specific folder,do Play console reject my app to use READ_EXTERNAL_STORAGE in my status saver application??
how can take that specific folder permission with DOCUMENT_TREE to not show that folder access denied??
I take DOCUMENT_TREE uri read permission, and i have to copy its video to other folder, so after all we find that if i can get actual path then i can copy that file to other Folder,some methods of get path shows Error No such directory, but finally a method shows access denied that folder.

Is it possible to access a document created using the intent with its path?

While working to upgrade to API 33 from API 28 I can no longer access the files that I have created with ACTION_CREATE_DOCUMENT intent without using its URI.
I have tried making sure to ensure READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions were taken before attempting to access the file. I manage to create the file but when creating its path and trying to access it at that path the app suddenly fails to open it even though it should be the owner of that file if I'm not wrong?
I absolutely cannot use MANAGE_EXTERNAL_STORAGE permission because that doesn't fit the usecase that I have.
Is there a way to use the path instead of the URI returned to write to the file? the file extension is csv.
I have created a sample to write and read the file.
Create the File:
Intent intent = new Intent(Intent.ActionCreateDocument);
intent.AddCategory(Intent.CategoryOpenable);
intent.SetType("application/txt");
intent.PutExtra(Intent.ExtraTitle, "anew.txt");
StartActivity(intent);
Then I saved the file into the Download Folder by the system file manager and write the file.
File.WriteAllText("/storage/emulated/0/Download/anew.txt", "this is file content");
Every thing worked well after I granted the storage permission to my app. But when I saved the file in the Documents Folder, I will get the error about accessing path /storage/emulated/0/Documents/anew.txt is denied.
The read and write storage permission cann't access the Documentss Folder with a path.

where does exactly getFilesDir() method address?

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.

How to download video from url and hide/secure this video from other apps and Gallery

One part of my current project is downloading Videos from URL then saving to SDCard. But the problem is all of saved videos in sdcard is displayed in android gallery page. What I want is "I don't want all of my saved vidoes in android gallery."
Create a .nomedia file inside the folder you don't want to be tracked by the MediaScanner. Maybe you'll need to rename the folder name after creating the file, since there is a bug that the MediaScanner (in some versions of android, not sure which one) fails to forget already-indexed files when it encounters a .nomedia file.

Install APK from assets or RAW folder

I would like to install an APK from within an Android application. Can anyone give me an example of how to do this?
EDIT:
Also how do I open the install applications from unknown resources preference page so that users can change it?
EDIT:
I actually meant open the screen using code, so I can immediately open the preference page for the user to simply check the box, and press back. Is it possible to check to see if they allow non-market apps?
Can an application request permission enough to do this?
use an intent with the link of your apk file.
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("http://movil.reforma.com/android/Android_Noticias_Reforma.apk"));
startActivity(intent);
install applications from unknown resources preference
go to
Settings > Applications > Unknow
sources

Categories