Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
bugfix in android versions >= N, needed workaround for FileUriExposed…
Browse files Browse the repository at this point in the history
…Exception
  • Loading branch information
sebastianknopf committed Feb 11, 2020
1 parent efe296a commit 4fa3f96
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.ggnome.viewer"
minSdkVersion 21
targetSdkVersion 29
versionCode 111
versionName "1.1.1"
versionCode 112
versionName "1.1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="file" />
<data android:mimeType="application/com.ggnome.ggpkg" />
</intent-filter>
</activity>
<activity
android:name=".InfoActivity"
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/ggnome/viewer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.ggnome.viewer.task.CacheCleanerTask;
import com.ggnome.viewer.view.GridViewItemSpacingDecoration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -110,9 +109,11 @@ public void onRequestPermissionsResult(final int requestCode, final @NonNull Str
// event handler
@Override
public void onItemClick(int position, String packageFileName) {
Uri packageFileUri = Uri.fromFile(new File(packageFileName));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(packageFileUri, "application/com.ggnome.ggpkg");
//Uri packageFileUri = Uri.fromFile(new File(packageFileName));

Intent intent = new Intent(this, ViewerActivity.class);
//intent.setDataAndType(packageFileUri, "application/com.ggnome.ggpkg");
intent.putExtra(ViewerActivity.EXTRA_FILE_NAME, packageFileName);
intent.putExtra(ViewerActivity.EXTRA_ENABLE_BACKWARDS_NAVIGATION, true);

this.startActivity(intent);
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/ggnome/viewer/ViewerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.ggnome.viewer.helper.GardenGnomePackage;
import com.ggnome.viewer.task.PackageLoaderTask;

import java.io.File;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
Expand All @@ -32,6 +34,8 @@
public class ViewerActivity extends AppCompatActivity {

public static String EXTRA_ENABLE_BACKWARDS_NAVIGATION = "EXTRA_ENABLE_BACKWARDS_NAVIGATION";
public static String EXTRA_FILE_NAME = "EXTRA_FILE_NAME";
public static String EXTRA_MIME_TYPE = "EXTRA_MIME_TYPE";

private ActivityViewerBinding activityViewerBinding;

Expand All @@ -53,7 +57,8 @@ protected void onCreate(Bundle savedInstanceState) {
}

// load package on first activity creation
this.loadPackageFile(this.getIntent().getData());
Uri fileUri = Uri.fromFile(new File(this.getIntent().getStringExtra(EXTRA_FILE_NAME)));
this.loadPackageFile(fileUri);
}

// init web view component with local asset loader
Expand Down Expand Up @@ -87,7 +92,8 @@ protected void onNewIntent(Intent intent) {
}

// load package on first activity creation
this.loadPackageFile(this.getIntent().getData());
Uri fileUri = Uri.fromFile(new File(this.getIntent().getStringExtra(EXTRA_FILE_NAME)));
this.loadPackageFile(fileUri);
}
}

Expand Down Expand Up @@ -234,7 +240,7 @@ private void leaveFullscreenMode() {
private void loadPackageFile(Uri uri) {
String packageFileName = null;
if(uri != null && uri.getScheme().equals("file")) {
packageFileName = this.getIntent().getData().getPath();
packageFileName = uri.getPath();
} else if(uri != null && uri.getScheme().equals("content")) {
// transform content uri into file uri
Cursor cursor = this.getContentResolver().query(uri, new String[] { MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DISPLAY_NAME }, null, null, null);
Expand Down

0 comments on commit 4fa3f96

Please sign in to comment.