为什么心不是我的手机震动,当我preSS的按钮? [英] Why isnt my phone vibrating when i press the button?

查看:130
本文介绍了为什么心不是我的手机震动,当我preSS的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试当用户点击一个按钮,手机振动使这种喜。继承人的manifest.xml和AndroidVibrator.java有啥错了吗?我该如何解决?谢谢!

继承人的清单文件:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=android.app
    安卓版code =1
    机器人:VERSIONNAME =1.0>
      <使用-权限的Andr​​oid:名称=android.permission.VIBRATE/>

    <使用-SDK安卓的minSdkVersion =7/>

    <应用

        机器人:图标=@可绘制/ ic_launcher

        机器人:标签=@字符串/ APP_NAME>
        <活动

            机器人:名称=。AndroidActivity
            机器人:标签=@字符串/ APP_NAME
            机器人:screenOrientation =画像>

            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>

                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
         <活动机器人:活性2NAME =
                   机器人:screenOrientation =画像
                   机器人:标签=@字符串/ APP_NAME>


         < /活性GT;

         <活动机器人:activity3NAME =
                   机器人:screenOrientation =画像
                   机器人:标签=@字符串/ APP_NAME>

         < /活性GT;

         <活动机器人:下一个名称=>

         < /活性GT;






    < /用途>




< /舱单>
 

继承人AndroidActivity:

 包android.app;
进口android.app.R;
进口android.app.Activity;
进口android.content.DialogInterface;
进口android.content.DialogInterface.OnClickListener;
进口android.os.Bundle;
进口android.view.View;
进口android.os.Vibrator;

公共类AndroidVibrator扩展活动实现OnClickListener
{
    私人查看MyView的;
    私人振动器myVib;

    @覆盖
    保护无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        myVib =(震动)this.getSystemService(VIBRATOR_SERVICE);

        // MyView的可以是任何类型的视图,按钮等
        MyView的=(查看)this.findViewById(R.id.sound);
        myView.setOnClickListener((android.view.View.OnClickListener)本);
    }

    公共无效的onClick(视图v)
    {
        myVib.vibrate(50);
        //添加任何你在这之后要
    }

    公共无效的onClick(DialogInterface为arg0,INT ARG1){
        // TODO自动生成方法存根

    }
}
 

解决方案

请确保你调用

 <使用-权限的Andr​​oid:名称=android.permission.VIBRATE/>
 

在您的清单

编辑:

尝试把你的许可,在清单的最后,还是以后的版本code。

Hi im trying to make it that when a user clicks on on a button the phone vibrates. Heres manifest.xml and AndroidVibrator.java so whats wrong? how can i fix it? thanks!

heres the manifest file:

<?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>

Heres 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

    }
}

解决方案

Make sure you call

  <uses-permission android:name="android.permission.VIBRATE" />

In your manifest

EDIT:

Try putting your permission at the end of the manifest, or after version code.

这篇关于为什么心不是我的手机震动,当我preSS的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆