我怎样才能做到这一点?我目前的代码如下所示:
final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.stat_sys_warning, System.currentTimeMillis());
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, Activity....class).putExtra(...);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, text, contentIntent);
manager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud) 我有一些设置可以启用/禁用某些动作的振动,但我发现如果设备没有振动能力则显示它们毫无意义.有没有办法检查此人是否正在使用iPod touch以及是否有振动?
我有一个计时器应用程序,我想在计时器完成后振动手机.我可以播放声音,直到按下OK按钮,但它只振动一次.在用户按下OK按钮之前,如何重复振动?
这是我目前的代码
SoundEffectInstance alarmSound = PlaySound(@"Alarms/"+alarmSoundString);
VibrateController vibrate = VibrateController.Default;
vibrate.Start(new TimeSpan(0,0,0,0,1000));
MessageBoxResult alarmBox = MessageBox.Show("Press OK to stop alarm", "Timer Finished", MessageBoxButton.OK);
if (alarmBox == MessageBoxResult.OK)
{
alarmSound.Stop();
vibrate.Stop();
}
Run Code Online (Sandbox Code Playgroud)
更新:我已经尝试了Joe的响应,如果我不调用MessageBox.Show()它可以工作它似乎在此点停止,直到按下OK.
我正在开发半双工VOIP通话应用程序.在那里我试图在地板交换期间与振动一起播放音调 - 进行地板交换以将讲话者从A改变为B或反之亦然以进行半双工呼叫.如果我尝试使用AudioServicesPlayAlertSound播放音调,那么它会在用户接听电话时播放声音,但不会在电话交换期间播放声音,因为呼叫音频可能存在混音问题.所以我用AVAudioPlayer的播放功能取代了AudioServicesPlayAlertSound.所以,现在我能够在通话期间完美地播放音调,即在地板交换期间,即它与VOIP呼叫音频混合良好.但是,如果我尝试使用AudioServicesPlayAlertSound添加振动功能,它不会振动设备,函数会被调用,但它不会生效.如果我评论出AVAudioPlayer' s功能播放音调,然后振动功能工作.有人可以建议我缺少什么吗?
片段:
NSLog(@"Play toneIncoming");
[_audioPlayerIncoming setDelegate:self];
[_audioPlayerIncoming play];
NSLog(@"vibrate now");
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//OR AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
我尝试了2个以上的振动功能,但是只有当我注释掉AVAudioPlayer的播放功能时才能工作,但我需要为VOIP呼叫的不同事件播放特定的音调,所以我也需要这个功能.
我使用这个好的库来检测Android设备上的抖动.一切都是好的!但在我的手机(索尼Xperia P)接收短信导致我的手机振动和震动检测到!
在像HTC Sensation XE这样的其他手机中,问题不存在.
有什么建议吗?
谢谢你的提前.
所以在我的应用程序中,我有一个搜索栏,允许用户设置铃声音量(0 - 100).我似乎找不到将铃声音量设置为指定数字的方法.我查看了AudioManager类,但它告诉我要么将ringermode设置为normal/silent/vibrate.那不是我想要的.我希望音量是一个特定的数字.这是我正在寻找的一个例子:
private void setRinger (int volume) // volume = 0 - 100
{
setRingVolume (volume); // Whenever a person gets a call/sms/warning/anything etc., it should be this volume.
}
Run Code Online (Sandbox Code Playgroud)
这在Android中可行吗?如果是这样,怎么样?你能告诉我一个如何做到这一点的例子吗?
谢谢.
我正在制作一个应用程序,一旦计时器达到一定的限制振动.
但是,在打电话时
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
Xcode出现两个错误:
Undefined symbols for architecture i386:
"_AudioServicesPlaySystemSound", referenced from:
-[drawGraph drawRect:] in drawGraph.o
ld: symbol(s) not found for architecture i386
Run Code Online (Sandbox Code Playgroud)
和
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
有关导致这些错误的原因的任何想法?
我正在尝试在本地通知上使用自定义振动。阅读了一些内容后,我在通知通道中设置了自定义振动模式,如下所示:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel =
NotificationChannel(NotificationChannels.CHANNEL_ID, channelName, importance)
...
notificationChannel.enableVibration(true)
notificationChannel.vibrationPattern = vibrationPattern
notificationManager.createNotificationChannel(notificationChannel)
}
Run Code Online (Sandbox Code Playgroud)
但它只振动一次,并且只执行前四个索引。
例如,如果我的模式如下所示:
val vibrationPattern = longArrayOf(
0, 200, 500, 50,
0, 200, 500, 50,
0, 200, 500, 50,
0, 200, 500, 50,
0, 200, 500, 50,
0, 200, 500, 50)
Run Code Online (Sandbox Code Playgroud)
它仅在第一行振动并停止。振动等效于:
val vibrationPattern = longArrayOf(0, 200, 500, 50)
Run Code Online (Sandbox Code Playgroud)
我有一个想法,将模式设置为看起来像最后一个,并将系统设置为重复几次,但到目前为止我还没有找到如何做到这一点。
我很高兴在这里得到一些帮助。
我目前正在C中编写一个包含游戏手柄支持的跨平台库.Windows上的游戏手柄通信由原始输入和xinput处理,具体取决于特定的游戏手柄.
虽然xinput有助于在xbox360控制器上进行力反馈,但我还没有找到使用原始输入执行此操作的方法.我有一些可以提供力反馈的游戏手柄,但我无法通过原始输入找到一种方法.有没有办法做到这一点?
我不喜欢使用directinput api,因为微软已经弃用它并且不鼓励它.
编辑:
由于我已经在很大程度上实现了游戏手柄,也许我可以稍微缩小这个问题.我怀疑通过读取HIDP_CAPS结构的NumberOutputValueCaps可以找到游戏手柄中的隆隆马达数量.这为我的所有测试游戏手柄提供了正确的结果.
我正在使用funtcion HidP_GetUsageValue来读取轴值,这很好.现在我怀疑调用HidP_SetUsageValue应该允许我改变这个输出值,打开隆隆电机.但是,调用此函数失败.该功能是否能够接入隆隆电机?
即使设备的振动反馈设置关闭,是否仍会振动手机?
我已经尝试过这段代码,但只有当从设置中打开振动反馈时它才会起作用。
await HapticFeedback.vibrate();
Run Code Online (Sandbox Code Playgroud)
我什至尝试过振动插件,但也不会取得成功。