あまりバイブ機能に関する記事がなかったので、書いてみる。
今回は、ボタンをクリック-->バイブの簡単なサンプルを載っける。
Vibe.java
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Vibe extends Activity {
private NotificationManager notificationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Notification notification = new Notification();
notification.vibrate = new long[]{0, 200, 100, 200, 100, 200};
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(R.string.app_name, notification);
}
});
}
}
notification.vibrate = new long[]{0, 200, 100, 200, 100, 200};*ココはバイブのOFF/ONの時間の指定(ミリ秒)
androidManifest.xml
*マニフェストへの記述は忘れがちっぽいから気をつけて~<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.VIBRATE"/> //<-----ココを追加
<application android:icon="@drawable/icon" android:label="@string/app_name" >