use of com.getcapacitor.JSArray in project capacitor-plugins by ionic-team.
the class CameraPlugin method requestPermissions.
@Override
@PluginMethod
public void requestPermissions(PluginCall call) {
// it is not defined in the manifest then we don't need to prompt and it will just work.
if (isPermissionDeclared(CAMERA)) {
// just request normally
super.requestPermissions(call);
} else {
// the manifest does not define camera permissions, so we need to decide what to do
// first, extract the permissions being requested
JSArray providedPerms = call.getArray("permissions");
List<String> permsList = null;
try {
permsList = providedPerms.toList();
} catch (JSONException e) {
}
if (permsList != null && permsList.size() == 1 && permsList.contains(CAMERA)) {
// the only thing being asked for was the camera so we can just return the current state
checkPermissions(call);
} else {
// we need to ask about photos so request storage permissions
requestPermissionForAlias(PHOTOS, call, "checkPermissions");
}
}
}
use of com.getcapacitor.JSArray 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.JSArray in project capacitor-plugins by ionic-team.
the class ActionSheetPlugin method showActions.
@PluginMethod
public void showActions(final PluginCall call) {
String title = call.getString("title");
JSArray options = call.getArray("options");
if (title == null) {
call.reject("Must supply a title");
return;
}
if (options == null) {
call.reject("Must supply options");
return;
}
if (getActivity().isFinishing()) {
call.reject("App is finishing");
return;
}
try {
List<Object> optionsList = options.toList();
ActionSheetOption[] actionOptions = new ActionSheetOption[optionsList.size()];
for (int i = 0; i < optionsList.size(); i++) {
JSObject o = JSObject.fromJSONObject((JSONObject) optionsList.get(i));
String titleOption = o.getString("title", "");
actionOptions[i] = new ActionSheetOption(titleOption);
}
implementation.setTitle(title);
implementation.setOptions(actionOptions);
implementation.setCancelable(false);
implementation.setOnSelectedListener(index -> {
JSObject ret = new JSObject();
ret.put("index", index);
call.resolve(ret);
implementation.dismiss();
});
implementation.show(getActivity().getSupportFragmentManager(), "capacitorModalsActionSheet");
} catch (JSONException ex) {
Logger.error("JSON error processing an option for showActions", ex);
call.reject("JSON error processing an option for showActions", ex);
}
}
use of com.getcapacitor.JSArray in project capacitor-plugins by ionic-team.
the class LocalNotificationsPlugin method registerActionTypes.
@PluginMethod
public void registerActionTypes(PluginCall call) {
JSArray types = call.getArray("types");
Map<String, NotificationAction[]> typesArray = NotificationAction.buildTypes(types);
notificationStorage.writeActionGroup(typesArray);
call.resolve();
}
use of com.getcapacitor.JSArray in project capacitor-plugins by ionic-team.
the class PushNotificationsPlugin method getDeliveredNotifications.
@PluginMethod
public void getDeliveredNotifications(PluginCall call) {
JSArray notifications = new JSArray();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
for (StatusBarNotification notif : activeNotifications) {
JSObject jsNotif = new JSObject();
jsNotif.put("id", notif.getId());
Notification notification = notif.getNotification();
if (notification != null) {
jsNotif.put("title", notification.extras.getCharSequence(Notification.EXTRA_TITLE));
jsNotif.put("body", notification.extras.getCharSequence(Notification.EXTRA_TEXT));
jsNotif.put("group", notification.getGroup());
jsNotif.put("groupSummary", 0 != (notification.flags & Notification.FLAG_GROUP_SUMMARY));
JSObject extras = new JSObject();
for (String key : notification.extras.keySet()) {
extras.put(key, notification.extras.get(key));
}
jsNotif.put("data", extras);
}
notifications.put(jsNotif);
}
}
JSObject result = new JSObject();
result.put("notifications", notifications);
call.resolve(result);
}
Aggregations