Vibrator permission force close

主宰稳场 提交于 2019-12-12 03:43:23

问题


I have this line of code calling 2 seconds from the vibrator_service;

 Vibrator v = (Vibrator)
                        getSystemService(Context.VIBRATOR_SERVICE);
                        v.vibrate(2000);

and this in my manifest

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

But I am still getting a force close java.lang.security.exception: Requires Vibrate Permission. Have I declared the permission wrong??


回答1:


You need to add a uses-permission tag in the manifest file (as a child of the manifest element, same as the permission tag):

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

As far as I know, the permission tag is only used to add additional text/graphic information to the permissions request when downloading the app, or to add new permissions to provide additional information to your users. I usually use both to be safe.



来源:https://stackoverflow.com/questions/12523265/vibrator-permission-force-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!