From 2dc8b3303c60b2e1cc8de3fe48eac70218288c71 Mon Sep 17 00:00:00 2001 From: Cyunrei Date: Tue, 11 Aug 2020 11:32:12 +0800 Subject: [PATCH] Fix crash after selected video below Android 8.0 --- .../java/com/cyunrei/videolivewallpaper/MainActivity.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/cyunrei/videolivewallpaper/MainActivity.java b/app/src/main/java/com/cyunrei/videolivewallpaper/MainActivity.java index 91949b3..ed3b606 100644 --- a/app/src/main/java/com/cyunrei/videolivewallpaper/MainActivity.java +++ b/app/src/main/java/com/cyunrei/videolivewallpaper/MainActivity.java @@ -90,13 +90,11 @@ public void onClick(View p1) { }); } - @TargetApi(Build.VERSION_CODES.DONUT) private void getPermission() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } - @TargetApi(Build.VERSION_CODES.GINGERBREAD) private void updateDialog() { final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); normalDialog.setTitle(getString(R.string.update_log) + "(" + getString(R.string.version_name) + ")"); @@ -119,18 +117,17 @@ private void chooseVideo() { startActivityForResult(intent, 1); } - @TargetApi(Build.VERSION_CODES.O) @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); assert uri != null; if ("file".equalsIgnoreCase(uri.getScheme())) { - copyFile(new File(Objects.requireNonNull(uri.getPath())), new File(getFilesDir().toPath() + "/file.mp4")); + copyFile(new File(Objects.requireNonNull(uri.getPath())), new File(getFilesDir() + "/file.mp4")); VideoLiveWallpaper.setToWallPaper(this); return; } - copyFile(new File(getPath(this, uri)), new File(getFilesDir().toPath() + "/file.mp4")); + copyFile(new File(getPath(this, uri)), new File(getFilesDir() + "/file.mp4")); VideoLiveWallpaper.setToWallPaper(this); }