Вот их образец.
plugin.xml
Код: Выделить всё
xmlns:android="http://schemas.android.com/apk/res/android">
VibrationPlugin
Plugin for vibrating the device
MIT
vibration, vibrate, cordova
Код: Выделить всё
{
"name": "cordova-plugin-vibrationplugin",
"version": "0.0.1",
"description": "An Android Cordova plugin that allows users to vibrate the device with different effects.",
"cordova": {
"id": "cordova-plugin-vibrationplugin",
"platforms": [
"android"
]
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [
"Vibration",
"Vibrate",
"Cordova",
"ecosystem:cordova",
"cordova-android"
],
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"author": "user",
"license": "MIT",
"bugs": {
"url": ""
},
"homepage": ""
}
Код: Выделить всё
var exec = require('cordova/exec');
var VibrationPlugin = {
vibrate: function(successCallback, errorCallback) {
exec(successCallback, errorCallback, 'VibrationPlugin', 'vibrate', []);
}
};
module.exports = VibrationPlugin;
Код: Выделить всё
package com.example.vibrationplugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
public class VibrationPlugin extends CordovaPlugin {
private static final String DURATION_LONG = "long";
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
// Verify that the user sent a 'vibrate' action
if (!action.equals("vibrate")) {
callbackContext.error("\"" + action + "\" is not a recognized action.");
return false;
}
// Extract message and duration from arguments
String duration;
try {
JSONObject options = args.getJSONObject(0);
duration = options.getString("duration");
} catch (JSONException e) {
callbackContext.error("Error encountered: " + e.getMessage());
return false;
}
// Vibrate the device
try {
Vibrator vibrator = (Vibrator) cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
VibrationEffect effect = VibrationEffect.createOneShot(1000, VibrationEffect.EFFECT_DOUBLE_CLICK);
vibrator.vibrate(effect);
} else {
// For devices below Android Oreo, fallback to simple vibration
vibrator.vibrate(1000);
}
callbackContext.success();
} else {
callbackContext.error("Vibrator service not available.");
}
} catch (Exception e) {
callbackContext.error("Error while vibrating: " + e.getMessage());
}
return true;
}
}
Я уже пробовал менять имена классов, переделывать весь плагин, изменять имена, но все равно не могу это исправить.
Подробнее здесь: https://stackoverflow.com/questions/786 ... in-cordova