安卓:振动法(?如果手机没有震动) [英] Android: vibrator method (if phone has no vibrator?)

查看:236
本文介绍了安卓:振动法(?如果手机没有震动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用振动器方法在我的应用程序,和我得到它的工作在我的手机里面有一个振动器这是伟大的。然而电话不具有一个振动器会发生什么。它不工作?它停止的应用程序工作?或者它不是在市场上露面呢?或者我要问的手机,如果它有一个振动器?

I want to use the vibrator method in my app, and i have got it working on my phone which has a vibrator which is great. however phones that don't have a vibrator what happens. does it not work at all? does it stop the app working? or does it not show up in the market at all? or do i have to ask the phone if it has a vibrator?

我也想知道,如果这code是好还是需要的任何调整?这里是我的code ..

I would also like to know if this code is good or needs any adjustments? here is my code..

Vibrator vi;

vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

vi.vibrate(100);

<uses-permission android:name="android.permission.VIBRATE" /> (In manifest)

谢谢,任何帮助将是巨大的。

Thanks, any help would be great.

推荐答案

检查文档,<一个href="http://developer.android.com/reference/android/os/Vibrator.html">http://developer.android.com/reference/android/os/Vibrator.html

所有你需要做的是检查是否有震动的手机,像这样的present:

all you need to do is check if a vibrator is present on the phone like so:

 Vibrator vi;

 vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

 if(vi.hasVibrator()){
     vi.vibrate(100);
 }

的震动权限的Andr​​oid市场由于的可能会过滤的您的应用程序只是手机用振动。为了避免这种情况,你可以使用标签与属性要求=假

Because of the vibrate permission Android market may filter your app to just phones with a vibrate. To avoid this you can use the tag with the attribute of required="false"

 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-feature android:name="there.isnt.a.vibrate.feature" android:required="false" />

这一切都记录在这里:

It's all documented here:

<一个href="http://developer.android.com/guide/topics/manifest/uses-permission-element.html">http://developer.android.com/guide/topics/manifest/uses-permission-element.html

<一个href="http://developer.android.com/guide/topics/manifest/uses-feature-element.html">http://developer.android.com/guide/topics/manifest/uses-feature-element.html

然而

没有一个振动特征串,因此Android电子市场的不会过滤您的应用程序,因为你正在使用的振动许可。所以,你确定只使用用途,权限和做在Java code检查。

There is not a Vibrate feature string, therefore Android Market Will Not filter your app because you are using the vibrate permission. So your ok to just use uses-permission and do the check in the Java code.

设备需要一个振动器与Android市场兼容的,但当然,这并不去亚马逊和其他应用程序市场(巴恩斯&安培; Noble Nook等不具有VIB)

Devices need a vibrator to be compatible with the android market, but of course this doesn't go for the amazon and other app markets (Barnes & Noble Nook doesn't have a vib).

这是支持由黛安Hackthorn(在谷歌的Andr​​oid牵头开发)回复此主题: <一href="http://groups.google.com/group/android-developers/browse_thread/thread/7713e796ea2d0f5f">http://groups.google.com/group/android-developers/browse_thread/thread/7713e796ea2d0f5f

This is backed up by Dianne Hackthorn (Android lead dev at Google's) reply to this thread: http://groups.google.com/group/android-developers/browse_thread/thread/7713e796ea2d0f5f

这篇关于安卓:振动法(?如果手机没有震动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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