use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class LocalNotificationsPlugin method requestPermissions.
@PluginMethod
public void requestPermissions(PluginCall call) {
JSObject permissionsResultJSON = new JSObject();
permissionsResultJSON.put("display", getNotificationPermissionText());
call.resolve(permissionsResultJSON);
}
use of com.getcapacitor.PluginMethod 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);
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class SharePlugin method share.
@PluginMethod
public void share(PluginCall call) {
if (!isPresenting) {
String title = call.getString("title", "");
String text = call.getString("text");
String url = call.getString("url");
String dialogTitle = call.getString("dialogTitle", "Share");
if (text == null && url == null) {
call.reject("Must provide a URL or Message");
return;
}
if (url != null && !isFileUrl(url) && !isHttpUrl(url)) {
call.reject("Unsupported url");
return;
}
Intent intent = new Intent(Intent.ACTION_SEND);
if (text != null) {
// If they supplied both fields, concat them
if (url != null && isHttpUrl(url))
text = text + " " + url;
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setTypeAndNormalize("text/plain");
}
if (url != null && isHttpUrl(url) && text == null) {
intent.putExtra(Intent.EXTRA_TEXT, url);
intent.setTypeAndNormalize("text/plain");
} else if (url != null && isFileUrl(url)) {
String type = getMimeType(url);
if (type == null) {
type = "*/*";
}
intent.setType(type);
Uri fileUrl = FileProvider.getUriForFile(getActivity(), getContext().getPackageName() + ".fileprovider", new File(Uri.parse(url).getPath()));
intent.putExtra(Intent.EXTRA_STREAM, fileUrl);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
intent.setDataAndType(fileUrl, type);
}
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
if (title != null) {
intent.putExtra(Intent.EXTRA_SUBJECT, title);
}
Intent chooser = null;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
// requestCode parameter is not used. Providing 0
PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, new Intent(Intent.EXTRA_CHOSEN_COMPONENT), PendingIntent.FLAG_UPDATE_CURRENT);
chooser = Intent.createChooser(intent, dialogTitle, pi.getIntentSender());
chosenComponent = null;
} else {
chooser = Intent.createChooser(intent, dialogTitle);
}
chooser.addCategory(Intent.CATEGORY_DEFAULT);
stopped = false;
isPresenting = true;
startActivityForResult(call, chooser, "activityResult");
} else {
call.reject("Can't share while sharing is in progress");
}
}
use of com.getcapacitor.PluginMethod 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.PluginMethod 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);
}
Aggregations