use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class DevicePlugin method getBatteryInfo.
@PluginMethod
public void getBatteryInfo(PluginCall call) {
JSObject r = new JSObject();
r.put("batteryLevel", implementation.getBatteryLevel());
r.put("isCharging", implementation.isCharging());
call.resolve(r);
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class DevicePlugin method getId.
@PluginMethod
public void getId(PluginCall call) {
JSObject r = new JSObject();
r.put("uuid", implementation.getUuid());
call.resolve(r);
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class DialogPlugin method alert.
@PluginMethod
public void alert(final PluginCall call) {
final AppCompatActivity activity = this.getActivity();
final String title = call.getString("title");
final String message = call.getString("message");
final String buttonTitle = call.getString("buttonTitle", "OK");
if (title == null || message == null) {
call.reject("Please provide a title or message for the alert");
return;
}
if (activity.isFinishing()) {
call.reject("App is finishing");
return;
}
Dialog.alert(activity, message, title, buttonTitle, (value, didCancel, inputValue) -> call.resolve());
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class DialogPlugin method prompt.
@PluginMethod
public void prompt(final PluginCall call) {
final AppCompatActivity activity = this.getActivity();
final String title = call.getString("title");
final String message = call.getString("message");
final String okButtonTitle = call.getString("okButtonTitle", "OK");
final String cancelButtonTitle = call.getString("cancelButtonTitle", "Cancel");
final String inputPlaceholder = call.getString("inputPlaceholder", "");
final String inputText = call.getString("inputText", "");
if (title == null || message == null) {
call.reject("Please provide a title or message for the alert");
return;
}
if (activity.isFinishing()) {
call.reject("App is finishing");
return;
}
Dialog.prompt(activity, message, title, okButtonTitle, cancelButtonTitle, inputPlaceholder, inputText, (value, didCancel, inputValue) -> {
JSObject ret = new JSObject();
ret.put("cancelled", didCancel);
ret.put("value", inputValue == null ? "" : inputValue);
call.resolve(ret);
});
}
use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.
the class AppPlugin method getInfo.
@PluginMethod
public void getInfo(PluginCall call) {
JSObject data = new JSObject();
try {
PackageInfo pinfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
ApplicationInfo applicationInfo = getContext().getApplicationInfo();
int stringId = applicationInfo.labelRes;
String appName = stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : getContext().getString(stringId);
data.put("name", appName);
data.put("id", pinfo.packageName);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
data.put("build", Long.toString(pinfo.getLongVersionCode()));
} else {
data.put("build", Integer.toString(pinfo.versionCode));
}
data.put("version", pinfo.versionName);
call.resolve(data);
} catch (Exception ex) {
call.reject("Unable to get App Info");
}
}
Aggregations