嗨即時嘗試使它,當用戶點擊按鈕手機振動。下面manifest.xml和AndroidVibrator.java所以最新的錯誤?我該如何解決它?謝謝!當我按下按鈕時,爲什麼手機沒有振動?
繼承人的清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AndroidActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity2"
android:screenOrientation="portrait"
android:label="@string/app_name" >
</activity>
<activity android:name=".activity3"
android:screenOrientation="portrait"
android:label="@string/app_name" >
</activity>
<activity android:name=".next" >
</activity>
</application>
</manifest>
繼承人AndroidActivity:
package android.app;
import android.app.R;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.os.Vibrator;
public class AndroidVibrator extends Activity implements OnClickListener
{
private View myView;
private Vibrator myVib;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
//myView can be any type of view, button, etc.
myView = (View) this.findViewById(R.id.sound);
myView.setOnClickListener((android.view.View.OnClickListener) this);
}
public void onClick(View v)
{
myVib.vibrate(50);
//add whatever you want after this
}
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
}
檢查手機設置,振動是否被禁用。 – Mani 2012-01-14 06:15:07
@Manik我剛開始在我的應用程序中使用共鳴,並測試關閉我的手機振動,所以後面和主頁按鈕不會盛傳,但我的應用程序仍然...我需要檢查用戶的手機目前是否有振動禁用,不做氛圍? – topwik 2012-09-05 19:03:09
@towpse你的應用程序共鳴哪個事件? 鍵盤按下或正常觸摸視圖? – Mani 2012-09-06 06:20:35