我使用以下代码片段以特定模式振动手机,但它会抛出和ArrayIndexOutOfBoundsException.
vibrator.vibrate(new long[] { selectedDuration, CONSTANT_DELAY }, REPEAT);
Run Code Online (Sandbox Code Playgroud)
但
vibrator.vibrate(VIBRATE_DURATION);
Run Code Online (Sandbox Code Playgroud)
工作良好.有什么指针吗?
我正在寻找如何改变Jelly Bean中的振动设置.我发现所有JB之前的振动设置都已被弃用,但是没有看到任何新的AudioManager.[更改振动设置]代码.有一个设置"振铃时振动",我想知道如何玩.
谢谢你的帮助.
android vibration android-audiomanager android-4.2-jelly-bean
我正计划按下一个按钮,按下按钮时振动开始并继续振动,直到手指向上或按钮未按下.
我正在使用Touch Listener来实现此目的.
我的代码如下:
package com.example.vibrator;
import android.app.Activity;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Vibrator vibrator;
vibrator = (Vibrator) getSystemService(MainActivity.VIBRATOR_SERVICE);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
vibrator.vibrate(60000);
} else if (action == MotionEvent.ACTION_UP) {
vibrator.cancel();
}
return true;
}
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在更改seekbar的值时实现触觉反馈。它可以在Android pre-P上正常运行。在Android P上根本不起作用。码:
private val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator?
private val effect by lazy { VibrationEffect.createOneShot(VIBRATION_DURATION, 50)}
...
fun vibrate() {
if (vibrator == null || !vibrator.hasVibrator()) {
return
}
vibrator.cancel()
vibrator.vibrate(effect)
Run Code Online (Sandbox Code Playgroud) 嘿伙计们,我仍然是一个Android和Java菜鸟,但我看到的一切都告诉我这应该完全奏效,但事实并非如此!不是在模拟器中,而是在手机上..我正在尝试使用振动器振动(500); ..我得到一个"应用程序意外停止"错误
我错过了什么?
代码如下:
package com.phys;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class phys extends Activity {
Vibrator vibr;
Button but;
TextView txt;
int counter = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vibr = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
but = (Button)findViewById(R.id.Button01);
txt = (TextView)findViewById(R.id.txt);
but.setOnClickListener(clk);
}
OnClickListener clk = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated …Run Code Online (Sandbox Code Playgroud) 我正在制作一个振动切换小部件(事实上,它的第一个版本已经在市场上)但我在Android 2.2的振动设置方面遇到了一些问题.
高达Android 2.1我没有问题,当我想禁用振动我做
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF);
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,AudioManager.VIBRATE_SETTING_OFF);
Run Code Online (Sandbox Code Playgroud)
和相同,但VIBRATE_SETTING_ON在两条线上打开它,它的工作正常.
但是,由于Android 2.2引入了"仅在静音模式下振动"和"在不在静音模式下振动",我不知道如何使其工作.当vibrate设置为"Always"或"Never"时没有问题,但是一旦用户手动将其设置为其他两个设置之一,应用程序就会开始做一些奇怪的事情.
例如,如果我将它设置为"仅在静音模式下振动"并且通过我的小部件关闭振动,它会关闭,但是当我重新打开它时它会返回"仅在静音模式下"而不是"永远".事实上,没有办法将它设置回"Always",除非你通过Settings - > Sound进行,所以我猜振动模式的组合框正在做一些我不知道的事情.就像它将值存储在其他地方一样,因为即使我手动设置为"Always",当我禁用它并通过小部件再次启用它(使用我之前发布的代码)时,它会一直回到"仅在静音模式下振动" ".
而且,AudioManager类中的"仅在静默模式下"(VIBRATE_SETTING_ONLY_SILENT)中有一个值,但当您将其设置为"仅当不处于静默模式"时,它使用VIBRATE_SETTING_ON,因此无法检测到它(不是我知道,我的意思是).
希望我没有太混乱,但我想提供所有可能的数据.所有这一切......
有谁知道如何正确处理2.2中的振动设置?为了完全禁用或启用振动,是否还有我必须设置或运行的其他变量?还是一种将手机"重置"到已知状态以便工作正常的方法?
重现问题的步骤(或者至少是其中一个问题)是:
通过设置菜单将振动设置为"仅在静音模式下".
通过小部件将振动设置为"从不":
setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
检查振动设置为"从不"的设置菜单.
通过小部件将振动设置为"始终":
setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
我想使用wiimote来控制没有红外传感器条的光标.我正在使用它的音高和滚动值.问题是,当音高接近0度时,滚动非常不稳定,当音高接近90度时,它本身非常不稳定,但滚动很好.我经常轮询wiimote,所以我平均最后20个音高和滚动值,我可以让光标移动到我想要的位置.唯一的问题是还有很多无法控制的震动.关于如何减少它的任何想法?(或者甚至在没有IR传感器的情况下获得更精确的位置?)
谢谢!
戴夫
当我选择UITableView中的单元格时,我尝试使用Vibration.
在我的didselectedRowAtIndexPath我已经把这个代码:
#pragma mark - DidselectRow
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//SPINNER
[spinner startAnimating];
//[self performSelector:@selector(pushDetailView:) withObject:tableView afterDelay:0.1];
int *riga = indexPath.row;
[NSThread detachNewThreadSelector:@selector(pushDetailView) toTarget:self withObject:riga];
////////////////////////////////////////////////////////////////////////////////
// VIBRATION ALLERT //
////////////////////////////////////////////////////////////////////////////////
// Issue vibrate
//AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
NSLog(@"Vibra?");
////////////////////////////////////////////////////////////////////////////////
// VIBRATION ALLERT FIN //
////////////////////////////////////////////////////////////////////////////////
NSLog(@"Seleziono l'immagine: %@", [photoTitles objectAtIndex:indexPath.row]);
//creo un'istanza di DettaglioView
DettaglioView *dettaglioImmagine = [[DettaglioView alloc] initWithNibName:@"DettaglioView" bundle:nil];
//Inseirsco il titolo nella Navigation BAR della vista
dettaglioImmagine.titoloSource = [photoTitles objectAtIndex:indexPath.row];
dettaglioImmagine.imageCoverSource = [photoURLsLargeImage objectAtIndex:indexPath.row];
NSLog(@"imageCoverSource: %@", …Run Code Online (Sandbox Code Playgroud) 现在,我想让设备在屏幕上显示结果时振动
MainActivity.java的某些部分
public void onResult(String result) {
String tres = "\n";
try {
JSONObject j = new JSONObject(result);
JSONObject j1 = j.getJSONObject("status");
int j2 = j1.getInt("code");
if(j2 == 0){
JSONObject metadata = j.getJSONObject("metadata");
if (metadata.has("custom_files")) {
JSONArray musics = metadata.getJSONArray("custom_files");
for(int i=0; i<musics.length(); i++) {
JSONObject tt = (JSONObject) musics.get(i);
String title = tt.getString("title");
tres = tres + (i+1) + ". Title: " + title + "\n";
}
}
}else{
tres = result;
}
} catch (JSONException e) { …Run Code Online (Sandbox Code Playgroud) 我用getSystemService(String)这种方式,我希望这个活动开始振动1秒钟.但是,错误说标题
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
mVibrator.vibrate(1000);
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答!
我在Android上使用AIDE,但无法振动。
相关代码如下:
import android.os.*;
Vibrator.vibrate((long)1000);
Run Code Online (Sandbox Code Playgroud)
它说(在.vibrate行上):“这里没有这样的参考。” 当我检查应用程序中的定义时,就在那里有Vibrator.vibrate。
怎么了 它一定很简单,但是解决方案不在Web或其他任何地方。