Skip to content
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

Merged
merged 17 commits into from
Apr 8, 2024

Conversation

VitorVieiraZ
Copy link
Contributor

No description provided.

@VitorVieiraZ VitorVieiraZ changed the title Android PDF file viewer and openLink function working WIP - Android PDF file viewer and openLink function working Apr 5, 2024
@VitorVieiraZ VitorVieiraZ changed the title WIP - Android PDF file viewer and openLink function working Android PDF file viewer and openLink function working Apr 5, 2024
Comment on lines 142 to 147
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 );
Copy link
Collaborator

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

Comment on lines 146 to 147
showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_GRANT_READ_URI_PERMISSION );
showFileIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
Copy link
Collaborator

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) {
Copy link
Collaborator

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 :)

Suggested change
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() );
Copy link
Collaborator

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

Copy link
Collaborator

@tomasMizera tomasMizera left a 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 :)

@tomasMizera
Copy link
Collaborator

Great job! 🚀

@tomasMizera
Copy link
Collaborator

@VitorVieiraZ Please fix c++ code convention and we can merge this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants