0
내 응용 프로그램을 3 초 동안 진동 시키지만 작동하지 않아 그 이유를 알 수 없습니다. 버튼을 클릭해도 아무런 변화가 없습니다. 처음에는 주 활동에서 시도했지만 동일한 결과가있었습니다.3 초 동안 장치를 진동시킬 수 없음
주요 활동
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final Button vibrateButton = new Button(this);
final Intent vibration = new Intent(this, MyService.class);
vibrateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startService(vibration);
}
});
}
서비스
public class MyService extends IntentService {
public MyService()
{
super("MyService");
}
@Override
protected void onHandleIntent(Intent vibration)
{
Vibrator vibe = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(3000);
}
}
당신이 Manifest.xml의 권한을 가지고 있습니까? –
notthetup