最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)調(diào)用震動的方法

 更新時間:2015年11月11日 14:56:14   作者:leeon  
這篇文章主要介紹了Android實現(xiàn)調(diào)用震動的方法,實例分析了Android中Vibrator類的調(diào)用與使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了Android實現(xiàn)調(diào)用震動的方法。分享給大家供大家參考,具體如下:

調(diào)用Android系統(tǒng)的震動,只需要一個類 那就是Vibrator ,這個類在hard包中,一看系統(tǒng)級的服務(wù),又要通過manifest.xml文件設(shè)置權(quán)限了

<?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類用來操作設(shè)備上的震動,如果你的線程退出了,那么啟動的震動也會停止

public void vibrate (long[] pattern, int repeat)
Since: API Level 1

Vibrate with a given pattern.  //根據(jù)給定的節(jié)奏震動

Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.

//傳遞一個整型數(shù)組作為關(guān)閉和開啟震動的持續(xù)時間,以毫秒為單位。第一個值表示等待震動開啟的毫秒數(shù),下一個值表示保持震動的毫秒數(shù),這個序列值交替表示震動關(guān)閉和開啟的毫秒數(shù)

To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.
//為了重復的按設(shè)定的節(jié)奏震動,傳遞index參數(shù)表示重復次數(shù),用-1表示不重復。

Parameters
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);
    /*
     * 想設(shè)置震動大小可以通過改變pattern來設(shè)定,如果開啟時間太短,震動效果可能感覺不到
     * */
    vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    long [] pattern = {100,400,100,400}; // 停止 開啟 停止 開啟
    vibrator.vibrate(pattern,2); //重復兩次上面的pattern 如果只想震動一次,index設(shè)為-1
  }
  public void onStop(){
    super.onStop();
    vibrator.cancel();
  }
}

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • 深入理解Android熱修復技術(shù)原理之so庫熱修復技術(shù)

    深入理解Android熱修復技術(shù)原理之so庫熱修復技術(shù)

    通常情況下,大多數(shù)人希望android下熱補丁方案能夠做到補丁的全方位修復,包括類修復/資源修復/so庫的修復。 這里主要介紹熱補丁之so庫修復思路
    2021-06-06
  • 詳解flutter engine 那些沒被釋放的東西

    詳解flutter engine 那些沒被釋放的東西

    這篇文章主要介紹了詳解flutter engine 那些沒被釋放的東西,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-07-07
  • Android VNDK使用及原理深入探究

    Android VNDK使用及原理深入探究

    這篇文章主要為大家介紹了Android VNDK使用及原理深入探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2024-01-01
  • 詳解android系統(tǒng)的定制

    詳解android系統(tǒng)的定制

    這篇內(nèi)容給大家分享了關(guān)于android系統(tǒng)的定制的一些步驟和基本知識點,有興趣的朋友參考學習下。
    2018-06-06
  • java創(chuàng)建線程的4種方式集合(最新整理)

    java創(chuàng)建線程的4種方式集合(最新整理)

    在Java中,創(chuàng)建線程有多種方式,每種方式都有其適用場景和優(yōu)缺點,下面給大家分享java創(chuàng)建線程的4種方式,感興趣的朋友一起看看吧
    2018-05-05
  • Android判斷wifi是5G還是2.4G

    Android判斷wifi是5G還是2.4G

    這篇文章給大家分享android區(qū)分wifi是5G還是2.4G的方法,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友參考下
    2016-12-12
  • Mac Android Studio安裝圖文教程

    Mac Android Studio安裝圖文教程

    本文主要介紹了Mac Android Studio安裝教程,文中通過圖文代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Android編程實現(xiàn)震動與振鈴的方法詳解

    Android編程實現(xiàn)震動與振鈴的方法詳解

    這篇文章主要介紹了Android編程實現(xiàn)震動與振鈴的方法,結(jié)合實例形式分析了Android實現(xiàn)震動與振鈴的Vibrator類及MediaPlayer類相關(guān)使用技巧,需要的朋友可以參考下
    2018-03-03
  • Android 捕獲錯誤日志的方法

    Android 捕獲錯誤日志的方法

    這篇文章主要介紹了Android 捕獲錯誤日志的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • Android Studio使用Profiler來完成內(nèi)存泄漏的定位

    Android Studio使用Profiler來完成內(nèi)存泄漏的定位

    這篇文章主要介紹了Android Studio使用Profiler來完成內(nèi)存泄漏的定位,幫助大家更好的理解和學習使用Android,感興趣的朋友可以了解下
    2021-03-03

最新評論

景东| 荆门市| 大英县| 新泰市| 南投县| 黄浦区| 马鞍山市| 星座| 久治县| 惠水县| 宜川县| 奎屯市| 从江县| 平邑县| 封丘县| 聊城市| 二连浩特市| 昌邑市| 高密市| 柏乡县| 通江县| 龙江县| 曲周县| 万宁市| 承德市| 邵东县| 永济市| 兴义市| 房产| 阳谷县| 久治县| 五河县| 元谋县| 阿拉善右旗| 永定县| 马关县| 娱乐| 山东省| 杂多县| 阜城县| 岱山县|