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);
}
}
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);
}
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);
}
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");
}
}
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;
}
Aggregations