use of com.getcapacitor.JSArray in project capacitor-plugins by ionic-team.
the class StoragePlugin method migrate.
@PluginMethod
public void migrate(PluginCall call) {
List<String> migrated = new ArrayList<>();
List<String> existing = new ArrayList<>();
Storage oldStorage = new Storage(getContext(), StorageConfiguration.DEFAULTS);
for (String key : oldStorage.keys()) {
String value = oldStorage.get(key);
String currentValue = storage.get(key);
if (currentValue == null) {
storage.set(key, value);
migrated.add(key);
} else {
existing.add(key);
}
}
JSObject ret = new JSObject();
ret.put("migrated", new JSArray(migrated));
ret.put("existing", new JSArray(existing));
call.resolve(ret);
}
use of com.getcapacitor.JSArray in project capacitor-plugins by ionic-team.
the class StoragePlugin method keys.
@PluginMethod
public void keys(PluginCall call) {
Set<String> keySet = storage.keys();
String[] keys = keySet.toArray(new String[0]);
JSObject ret = new JSObject();
try {
ret.put("keys", new JSArray(keys));
} catch (JSONException ex) {
call.reject("Unable to serialize response.", ex);
return;
}
call.resolve(ret);
}
use of com.getcapacitor.JSArray in project capacitor-sms by moberwasserlechner.
the class SmsManagerPlugin method sendSms.
private void sendSms(final PluginCall call) {
JSArray numberArray = call.getArray("numbers");
List<String> recipientNumbers = null;
try {
recipientNumbers = numberArray.toList();
} catch (JSONException ignore) {
}
if (recipientNumbers == null || recipientNumbers.isEmpty()) {
call.reject(ERR_NO_NUMBERS);
return;
}
String text = ConfigUtils.getCallParam(String.class, call, "text");
if (text == null || text.length() == 0) {
call.reject(ERR_NO_TEXT);
return;
}
String separator = ";";
if (android.os.Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
// See http://stackoverflow.com/questions/18974898/send-sms-through-intent-to-multiple-phone-numbers/18975676#18975676
separator = ",";
}
String phoneNumber = getJoinedNumbers(recipientNumbers, separator);
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body", text);
// See http://stackoverflow.com/questions/7242190/sending-sms-using-intent-does-not-add-recipients-on-some-devices
smsIntent.putExtra("address", phoneNumber);
smsIntent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
if (smsIntent.resolveActivity(getContext().getPackageManager()) != null) {
startActivityForResult(call, smsIntent, "onSmsRequestResult");
} else {
call.reject(ERR_SERVICE_NOTFOUND);
}
}
use of com.getcapacitor.JSArray in project google-maps by capacitor-community.
the class CapacitorGoogleMaps method addPolygon.
@PluginMethod()
public void addPolygon(final PluginCall call) {
final JSArray points = call.getArray("points", new JSArray());
getBridge().executeOnMainThread(new Runnable() {
@Override
public void run() {
PolygonOptions polygonOptions = new PolygonOptions();
for (int i = 0; i < points.length(); i++) {
try {
JSONObject point = points.getJSONObject(i);
LatLng latLng = new LatLng(point.getDouble("latitude"), point.getDouble("longitude"));
polygonOptions.add(latLng);
} catch (JSONException e) {
e.printStackTrace();
}
}
googleMap.addPolygon(polygonOptions);
call.resolve();
}
});
}
use of com.getcapacitor.JSArray in project capacitor-firebase by robingenz.
the class OAuthProviderHandler method applySignInConfig.
private void applySignInConfig(PluginCall call, OAuthProvider.Builder provider) {
JSArray customParameters = call.getArray("customParameters");
if (customParameters != null) {
try {
List<Object> customParametersList = customParameters.toList();
for (int i = 0; i < customParametersList.size(); i++) {
JSObject customParameter = JSObject.fromJSONObject((JSONObject) customParametersList.get(i));
String key = customParameter.getString("key");
String value = customParameter.getString("value");
if (key == null || value == null) {
continue;
}
provider.addCustomParameter(key, value);
}
} catch (JSONException exception) {
Log.e(FirebaseAuthenticationPlugin.TAG, "applySignInConfig failed.", exception);
}
}
}
Aggregations