procedure OpenMyPDF(AFileName: string); var LIntent : JIntent; LFile : JFile; LFileName: string; begin // NOTE: You will need a PDF viewer installed on your device in order for this to work // TPath.GetHomePath = app dir LFileName := TPath.Combine(TPath.GetDocumentsPath, AFileName); if FileExists(AFileName) then begin LFile := TJFile.JavaClass.init(StringToJString(LFileName)); // LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW); LIntent.setDataAndType(TAndroidHelper.JFileToJURI(LFile), StringToJString('application/pdf')); LIntent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION); // TAndroidHelper.Activity.startActivity(LIntent); end else ShowMessage('File not found'); end;
procedure TForm1.Button1Click(Sender: TObject); begin OpenMyPDF('firebird.pdf'); end;
end.
---------- IF NECESSARY CREATE A NEW FILE: "provider_paths.xml" ---------- and ADD IT IN YOUR PROJECT --> "res\xml\"
0) check mark in "Project -> Options -> Entitlement list -> Secure file sharing 1) change the "provider_paths.xml" file 2) add it in your "Deploy menu options" in Android 32 or 64 setting ..... - UNCHECK the ORIGINAL entries... 3) build and deploy it to smartphone
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
you need test if is necessary in your Android version.
Im using Android 11, then many things was changed after v10...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
1) you needs ALWAYS say what your environment!!! -- what operating system Android version? -- what Android level API used? -- what RAD Studio/Delphi used? -- etc...
in Android, like others OS, each version is a new version!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
--> MIME identifation of each object type to work/open LIntent.setDataAndType(TAndroidHelper.JFileToJURI(LFile), StringToJString('application/pdf'));
--> "application/pdf" = any app installed that can "open/view" the file indicated in your "intent", in the case: "LFIle" == your pdf path
you need see "what MIME" will be used for your "picture/image"
image/* = ALL = ANY app to image image/bmp image/png
application/json application/docx application/pdf
text/plain
etc...
ALL official MIME types https://www.iana.org/assignments/media-types/media-types.xhtml
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
basically, when you execute a "intent", when the task is ended, you go back to activity before...
NOTE: each "Activity" is like "micro-tasks", then a Android app is filled of mini-tasks-apps... ... when a activity end, the before activity would called ...
A bad comparing... would be: In Delphi, when us "closing" a Form, then, go back to before "Form", or the app is ended because there is no more "Forms" to call...
do you understand this?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
here, it's a complicated situation... because is dependent of each Android edition!
After Android 10++++, many things about "security" was changed!!! In Android 11++, the things stay more rigid about access files in any folder that "is not from app"... by default, you can see all files that you app created, or files that are in your app folder install, or in public folder of Android (see in your Help )
Then, you (basically) can not see, read, write, etc... any files that is not "YOUR"!
But, the Android allow that your use a "special permission" that you can can bypass this barrier, however, some system folders will not be accessible anyway. NOTE: if your app will be hosted in a Google-Play, it can not be accepted! Because ONLY some company can use this permission... like Antivirus, File Managers, and a little others authorized!!!
Basically, the folders where Android installs the operating system and some other related folders, will not allow any regular user access!
You need read about this in Android Developer official site, because exists many situation and conditions for this! https://developer.android.com/docs?hl=zh-cn
---- read about this Permissions for Android 11++++
--- MANAGE_ALL_FILES_ACCESS_PERMISSION <-- this permission is the "magic thing" --- ACTION_OPEN_DOCUMENT_TREE --- MANAGE_DOCUMENTS --- MANAGE_EXTERNAL_STORAGE --- MANAGE_MEDIA <-- to audio, video and image
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
你现在明白了么? 也许是翻译文本时出现错误。 ---------- I didn't say "IMPOSSIBLE"!!! I said "COMPLICATED"
First, Google made security stronger against harmful applications, so now it is more "complicated" to give access to all (or almost all) file folders on an Android smartphone. (I think it's the same on iPhone, or even more difficult)
However, Google allows your application to access most file folders on your Android cell phone, however, if you want to distribute your application using the "Google-Play" platform, you must request special permission for the platform, if your application needs to use special permissions, such as "access to all files on Android". This is an irrevocable condition for the "Google-Play" platform.
On the other hand, if you are not going to distribute your application through the "Google-Play" platform, then you can, at your discretion, use special permissions in your applications. But either way, who will grant permission or not is the end user of your application. There's no other way!
Such special permissions, for example, for full access to files on the Android cell phone, are directed to software companies that require these permissions, such as Antivirus, Firewall applications, among others such as "WPS Office".
Do you understand now? Maybe it was an error in translating the text.
---------- android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION <-- this CALL (using Intents) makes some of the magic happen!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
Android 11+++ ---------- to call the Android screen for "Access all files" you can use a "Intent" and set a "Action" with "android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION" string... some like this:
---------- AndroidManifestTemplate.xml ... <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
if >= Android 11 ... android.permission.MANAGE_EXTERNAL_STORAGE <-- read all folders not SYSTEM(s)!!!
if < Android 11 ... android.permission.READ_EXTERNAL_STORAGE ... android.permission.WRITE_EXTERNAL_STORAGE
---------- 2) if >= Android 11 ... use a "Intent" ACTION to ask "ACCESS ALL FILES" for user --- android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION = any file type
if < Android 11 ... use "require permissions as usual..."
3) now, IF the permission OK, then, use TPath record for easy way:
const ... LRootOnAndroid:string = '/storage/emulated/0'; var ... LFolders:TArray<string>; ... LFiles:TArray<string>; begin ... LFolders := TDirectory.GetDirectories( LRootOnAndroid ); // path initial...if not exception ... for var D in LFolders do // if any folder was found... ....begin ....... LFiles := TDirectory.GetFiles( D ); ......... etc etc etc ....end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
if possible, I would like to see your code, if not confidential. I want to learn from your knowledge. if you can send it by email emailx45 @ yahoo com br
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3