Search in sources :

Example 1 with ActivityCallback

use of com.getcapacitor.annotation.ActivityCallback in project capacitor-file-picker by robingenz.

the class FilePickerPlugin method pickFilesResult.

@ActivityCallback
private void pickFilesResult(PluginCall call, ActivityResult result) {
    if (call == null) {
        return;
    }
    boolean readData = call.getBoolean("readData", true);
    int resultCode = result.getResultCode();
    switch(resultCode) {
        case Activity.RESULT_OK:
            JSObject callResult = createPickFilesResult(result.getData(), readData);
            call.resolve(callResult);
            break;
        case Activity.RESULT_CANCELED:
            call.reject(ERROR_PICK_FILE_CANCELED);
            break;
        default:
            call.reject(ERROR_PICK_FILE_FAILED);
    }
}
Also used : JSObject(com.getcapacitor.JSObject) ActivityCallback(com.getcapacitor.annotation.ActivityCallback)

Example 2 with ActivityCallback

use of com.getcapacitor.annotation.ActivityCallback in project capacitor-plugins by ionic-team.

the class CameraPlugin method processPickedImage.

@ActivityCallback
public void processPickedImage(PluginCall call, ActivityResult result) {
    settings = getSettings(call);
    Intent data = result.getData();
    if (data == null) {
        call.reject("No image picked");
        return;
    }
    Uri u = data.getData();
    imagePickedContentUri = u;
    processPickedImage(u, call);
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) ActivityCallback(com.getcapacitor.annotation.ActivityCallback)

Example 3 with ActivityCallback

use of com.getcapacitor.annotation.ActivityCallback in project capacitor-plugins by ionic-team.

the class CameraPlugin method processCameraImage.

@ActivityCallback
public void processCameraImage(PluginCall call, ActivityResult result) {
    settings = getSettings(call);
    if (imageFileSavePath == null) {
        call.reject(IMAGE_PROCESS_NO_FILE_ERROR);
        return;
    }
    // Load the image as a Bitmap
    File f = new File(imageFileSavePath);
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    Uri contentUri = Uri.fromFile(f);
    Bitmap bitmap = BitmapFactory.decodeFile(imageFileSavePath, bmOptions);
    if (bitmap == null) {
        call.reject("User cancelled photos app");
        return;
    }
    returnResult(call, bitmap, contentUri);
}
Also used : Bitmap(android.graphics.Bitmap) BitmapFactory(android.graphics.BitmapFactory) File(java.io.File) Uri(android.net.Uri) ActivityCallback(com.getcapacitor.annotation.ActivityCallback)

Example 4 with ActivityCallback

use of com.getcapacitor.annotation.ActivityCallback in project capacitor-plugins by ionic-team.

the class CameraPlugin method processPickedImages.

@ActivityCallback
public void processPickedImages(PluginCall call, ActivityResult result) {
    Intent data = result.getData();
    if (data != null) {
        Executor executor = Executors.newSingleThreadExecutor();
        executor.execute(() -> {
            JSObject ret = new JSObject();
            JSArray photos = new JSArray();
            if (data.getClipData() != null) {
                int count = data.getClipData().getItemCount();
                for (int i = 0; i < count; i++) {
                    Uri imageUri = data.getClipData().getItemAt(i).getUri();
                    JSObject processResult = processPickedImages(imageUri);
                    if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
                        call.reject(processResult.getString("error"));
                        return;
                    } else {
                        photos.put(processResult);
                    }
                }
            } else if (data.getData() != null) {
                Uri imageUri = data.getData();
                JSObject processResult = processPickedImages(imageUri);
                if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
                    call.reject(processResult.getString("error"));
                    return;
                } else {
                    photos.put(processResult);
                }
            } else if (data.getExtras() != null) {
                Bundle bundle = data.getExtras();
                if (bundle.keySet().contains("selectedItems")) {
                    ArrayList<Parcelable> fileUris = bundle.getParcelableArrayList("selectedItems");
                    if (fileUris != null) {
                        for (Parcelable fileUri : fileUris) {
                            if (fileUri instanceof Uri) {
                                Uri imageUri = (Uri) fileUri;
                                try {
                                    JSObject processResult = processPickedImages(imageUri);
                                    if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
                                        call.reject(processResult.getString("error"));
                                        return;
                                    } else {
                                        photos.put(processResult);
                                    }
                                } catch (SecurityException ex) {
                                    call.reject("SecurityException");
                                }
                            }
                        }
                    }
                }
            }
            ret.put("photos", photos);
            call.resolve(ret);
        });
    } else {
        call.reject("No images picked");
    }
}
Also used : Executor(java.util.concurrent.Executor) Bundle(android.os.Bundle) JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) Intent(android.content.Intent) Parcelable(android.os.Parcelable) Uri(android.net.Uri) ActivityCallback(com.getcapacitor.annotation.ActivityCallback)

Example 5 with ActivityCallback

use of com.getcapacitor.annotation.ActivityCallback in project capacitor-plugins by ionic-team.

the class SharePlugin method activityResult.

@ActivityCallback
private void activityResult(PluginCall call, ActivityResult result) {
    if (result.getResultCode() == Activity.RESULT_CANCELED && !stopped) {
        call.reject("Share canceled");
    } else {
        JSObject callResult = new JSObject();
        callResult.put("activityType", chosenComponent != null ? chosenComponent.getPackageName() : "");
        call.resolve(callResult);
    }
    isPresenting = false;
}
Also used : JSObject(com.getcapacitor.JSObject) ActivityCallback(com.getcapacitor.annotation.ActivityCallback)

Aggregations

ActivityCallback (com.getcapacitor.annotation.ActivityCallback)6 Uri (android.net.Uri)4 Intent (android.content.Intent)3 JSObject (com.getcapacitor.JSObject)3 Bundle (android.os.Bundle)2 Activity (android.app.Activity)1 Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Parcelable (android.os.Parcelable)1 ActivityResult (androidx.activity.result.ActivityResult)1 ActivityResultLauncher (androidx.activity.result.ActivityResultLauncher)1 ActivityResultContracts (androidx.activity.result.contract.ActivityResultContracts)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 ActivityCompat (androidx.core.app.ActivityCompat)1 JSArray (com.getcapacitor.JSArray)1