Skip to content

Commit

Permalink
adjustments for newer android versions
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed May 15, 2024
1 parent 23c5464 commit 30be2eb
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app/android/src/uk/co/lutraconsulting/InputActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.graphics.Insets;
import android.graphics.Color;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.content.ActivityNotFoundException;
Expand All @@ -41,6 +42,7 @@
public class InputActivity extends QtActivity
{
private static final String TAG = "Mergin Maps Input Activity";
private static final int OPEN_FILE_REQUEST_CODE = 1;
private boolean keepSplashScreenVisible = true;

@Override
Expand Down Expand Up @@ -125,31 +127,37 @@ public void hideSplashScreen()
public boolean openFile( String filePath ) {
File file = new File( filePath );

if ( !file.exists() ) {
if ( !file.exists() )
{
return false;
}

Intent showFileIntent = new Intent( Intent.ACTION_VIEW );

try {
try
{
Uri fileUri = FileProvider.getUriForFile( this, "uk.co.lutraconsulting.fileprovider", file );

showFileIntent.setData( fileUri );

// FLAG_GRANT_READ_URI_PERMISSION grants temporary read permission to the content URI.
// FLAG_ACTIVITY_NEW_TASK is used when starting an Activity from a non-Activity context.
showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION );
} catch ( IllegalArgumentException e ) {
}
catch ( IllegalArgumentException e )
{
return false;
}

if ( showFileIntent.resolveActivity( getPackageManager() ) != null ) {
startActivity( showFileIntent );
} else {
return false;
try
{
startActivityForResult( showFileIntent, OPEN_FILE_REQUEST_CODE );
return true;
}
catch ( ActivityNotFoundException ex )
{
return false;
}

return true;
}

public void quitGracefully()
Expand Down

0 comments on commit 30be2eb

Please sign in to comment.