Androidは振動を呼び起こす方法を実現します。

3539 ワード

この例は、Androidが振動を呼び起こす方法を実現することを示す。皆さんに参考にしてあげます。具体的には以下の通りです。
Androidシステムの振動を起動するには、一つだけの種類が必要です。これはVibratorです。hardパッケージの中で、システムレベルのサービスを見ると、またmaifest.xmlファイルを通じて権限を設定します。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="uni.vibrator"
   android:versionCode="1"
   android:versionName="1.0">
  <uses-sdk android:minSdkVersion="8" />
  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".VibratorDemoActivity"
         android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
   <uses-permission android:name="android.permission.VIBRATE" />
</manifest>

SDKを一緒に勉強しましょう。
Class that operates the vibrator on the device.
If your process exits、any vibration you started with will stop.
//Vibrator類は設備上の振動を操作するために使われています。もしスレッドが終了したら、起動の振動も停止します。
public void vibrate(long[]pattern,int repeat)
Since:API Level 1
Vibrate with a given pattern.  //与えられたリズムに従って振動する
Pass in array of ints that arararare the duratins for which to turn on on on of the vibbratoin mimimimimiliconds.The first value indicates thenumbebebebebebebebebebebebebebebebebebebei i i mimimiliconds to beitititititititbebebebeberning the the vibbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbratototototototototoon.Tht.Tht The nexThe nexxThe nexTht thethethethethethethenexxxxxxxxxxname between durations in miliseconds to turn the vibratooff or to turn the vibraton.
//1つの整体配列をオフとオープン振動の持続時間として伝え、ミリ秒単位で。最初の値は振動開始待ちのミリ秒数を表し、次の値は振動保持のミリ秒数を表します。このシーケンス値は振動オフとオープンのミリ秒数を交互に表します。
To cause the pattern to repeat、pass the index into the pattern array at which to start the repeat、or-1 to disable repeat.
//繰り返し設定されたリズムで振動するために、転送indexパラメータは繰り返し回数を表し、-1で重複しないことを表します。
パラメータ
pattern     an array of longs of times for which to turn the vibrator on or off.
repeat     the index into pattern at which to repeat,or-1 if you don't want to repeat.
振動をキャンセルするためのcancelという方法も含まれています。
セグメントのデモコードを見る:

/*
 * @author octobershiner
 * SE.HIT
 *     android     demo
 * */
package uni.vibrator;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
public class VibratorDemoActivity extends Activity {
  private Vibrator vibrator;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /*
     *              pattern   ,        ,          
     * */
    vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    long [] pattern = {100,400,100,400}; //            
    vibrator.vibrate(pattern,2); //       pattern         ,index  -1
  }
  public void onStop(){
    super.onStop();
    vibrator.cancel();
  }
}
ここで述べたように、皆さんのAndroidプログラムの設計に役に立ちます。