按下按钮时手机不振动?

时间:2012-01-15 01:16:05

标签: android

  

可能重复:
  Why isnt my phone vibrating when i press the button?

您好我试图让用户点击按钮时手机会振动。继承人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:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".activity3"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

         <activity
            android:name=".AndroidVibrator"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>

        <activity android:name=".next" >
        </activity>
    </application>

</manifest>

继承AndroidVibrator,我是否正确地声明了它的活动?我错过了什么?:

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(500);
        //add whatever you want after this
    }

    public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub

    }
}

我没有得到错误,按下按钮时它不会振动。谢谢你的帮助!

0 个答案:

没有答案