This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
@@ -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
}
@@ -0,0 +1,5 @@
{
"dependencies": {
"x_library_s": "./lib/x_library_s.har"
}
}
@@ -0,0 +1,17 @@
import { x_vibrator } from "x_library_s";
import { BusinessError } from "@kit.BasicServicesKit";
/**
* 震动
* @param {number} duriation 震动时间单位ms
*/
export function vibrator(duriation : number) : boolean {
try {
x_vibrator(duriation)
} catch (err) {
let e : BusinessError = err as BusinessError;
console.error(e.message);
return false;
}
return true;
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array/>
</dict>
</plist>
@@ -0,0 +1,3 @@
{
"deploymentTarget": "9"
}
@@ -0,0 +1,26 @@
import * as AudioToolbox from 'AudioToolbox';
import * as UIKit from 'UIKit';
import { Thread } from 'Foundation';
/**
* 震动
* @param {number} duriation 震动时间单位ms,ios 13.+有用。
*/
export function vibrator(duriation : number):boolean {
if (UTSiOS.available("iOS 13.0, *")) {
let generator = new UIKit.UIImpactFeedbackGenerator(style = UIKit.UIImpactFeedbackGenerator.FeedbackStyle.medium)
generator.prepare();
let start = new Date().getTime();
let end = start + duriation
while(start<end){
generator.impactOccurred(intensity = 0.5);
Thread.sleep(forTimeInterval = 0.1)
start = new Date().getTime();
}
}else{
AudioToolbox.AudioServicesPlayAlertSound(AudioToolbox.kSystemSoundID_Vibrate)
}
return true;
}
@@ -0,0 +1,16 @@
/**
* 震动
* @param {number} duriation 震动时间单位ms,ios,微信没有用。
*/
export function vibrator(duriation : number):boolean {
wx.vibrateShort({
type:"medium",
success() {
},
fail(error) {
console.error("微信:震动失败")
}
})
return true;
}
@@ -0,0 +1,12 @@
/**
* 震动
* @param {number} duriation 震动时间单位ms,ios,微信没有用。
*/
export function vibrator(duriation : number):boolean {
try {
navigator.vibrate(duriation);
} catch (error) {
console.error("WEB震动失败:",error)
}
return true;
}