Jac*_*dge 6 methods android vibration
我想在我的应用程序中使用振动器方法,我已经让它在我的手机上工作,它有一个伟大的振动器.但是没有振动器的手机会发生什么.它根本不起作用吗?它会阻止应用程序运行吗?还是根本没有出现在市场上?或者我是否必须询问手机是否有振动器?
我还想知道这段代码是好还是需要调整?这是我的代码..
Vibrator vi;
vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vi.vibrate(100);
<uses-permission android:name="android.permission.VIBRATE" /> (In manifest)
Run Code Online (Sandbox Code Playgroud)
谢谢,任何帮助都会很棒.
Blu*_*ell 17
查看文档,http://developer.android.com/reference/android/os/Vibrator.html
您需要做的就是检查手机上是否有振动器,如下所示:
Vibrator vi;
vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if(vi.hasVibrator()){
vi.vibrate(100);
}
Run Code Online (Sandbox Code Playgroud)
由于振动许可,Android市场可能会将您的应用程序过滤为只有振动的手机.为避免这种情况,您可以使用属性为required ="false"的标记
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="there.isnt.a.vibrate.feature" android:required="false" />
Run Code Online (Sandbox Code Playgroud)
这里都记录了:
http://developer.android.com/guide/topics/manifest/uses-permission-element.html
http://developer.android.com/guide/topics/manifest/uses-feature-element.html
然而
没有Vibrate功能字符串,因此Android Market 不会过滤您的应用,因为您正在使用振动权限.所以你可以使用uses-permission并检查Java代码.
设备需要振动器才能与Android市场兼容,但当然这不适用于亚马逊和其他应用市场(Barnes&Noble Nook没有振动).
这是由Dianne Hackthorn(Google的Android主要开发人员)回复此主题支持的:http://groups.google.com/group/android-developers/browse_thread/thread/7713e796ea2d0f5f
| 归档时间: |
|
| 查看次数: |
6630 次 |
| 最近记录: |