1
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
package="io.dcloud.uni_modules.xVibrateS">
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "19"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import Vibrator from "android.os.Vibrator"
|
||||
import Context from 'android.content.Context'
|
||||
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms
|
||||
*/
|
||||
export function vibrator(duriation : number):boolean {
|
||||
try {
|
||||
const context = UTSAndroid.getAppContext() as Context
|
||||
let vb = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator;
|
||||
if (vb!.hasVibrator()) {
|
||||
vb!.vibrate(duriation.toLong());
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user