diff --git a/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java b/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java index aeb76e1b..92e8fcbf 100644 --- a/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java +++ b/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java @@ -1,72 +1,70 @@ package org.kde.kdeconnect.Plugins.PhotoPlugin; import android.content.Intent; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import org.kde.kdeconnect.BackgroundService; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.FileProvider; public class PhotoActivity extends AppCompatActivity { private Uri photoURI; - private PhotoPlugin plugin; @Override protected void onStart() { super.onStart(); - BackgroundService.RunWithPlugin(this, getIntent().getStringExtra("deviceId"), PhotoPlugin.class, plugin -> this.plugin = plugin); - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ignored) { } // Continue only if the File was successfully created if (photoFile != null) { photoURI = FileProvider.getUriForFile(this, "org.kde.kdeconnect_tp.fileprovider", photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, 1); } } } private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); return File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - - if (resultCode == -1) { - plugin.sendPhoto(photoURI); - } else { - plugin.sendCancel(); - } + BackgroundService.RunWithPlugin(this, getIntent().getStringExtra("deviceId"), PhotoPlugin.class, plugin -> { + if (resultCode == -1) { + plugin.sendPhoto(photoURI); + } else { + plugin.sendCancel(); + } + }); finish(); } }