-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android PDF file viewer and openLink function working #3268
Conversation
Uri fileUri = FileProvider.getUriForFile( this, "uk.co.lutraconsulting.fileprovider", file ); | ||
Log.d( TAG, "File URI: " + fileUri.toString() ); | ||
|
||
showFileIntent.setData( fileUri ); | ||
showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_GRANT_READ_URI_PERMISSION ); | ||
showFileIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you need to do all of these steps prior to calling showFileIntent.resolveActivity
. The way you implement it now you tell Android that you want to open something and ask it if it has an app for that. But it does not know what you are trying to open.
You should first set all these setData
,setFlags
and only after that call the check to see if there is any app that can open what you want
showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_GRANT_READ_URI_PERMISSION ); | ||
showFileIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a comment please why we need these flags and what they do?
@@ -115,6 +122,41 @@ public void hideSplashScreen() | |||
keepSplashScreenVisible = false; | |||
} | |||
|
|||
public void showPDF(String filePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename the method as it is now file-type-agnostic :)
public void showPDF(String filePath) { | |
public void openFile(String filePath) { |
} | ||
} | ||
else { | ||
runOnUiThread(() -> Toast.makeText( getApplicationContext(), "No application for opening this file", Toast.LENGTH_SHORT).show() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need that runOnUiThread
? Just asking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this now and continue working in a new PR :)
Great job! 🚀 |
@VitorVieiraZ Please fix c++ code convention and we can merge this one |
No description provided.