需要示例android蓝牙权限代码
我需要一个蓝牙权限的示例java代码。 Android 12。
我知道我必须将其放入 AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH"/>
根据我的研究,我认为我必须使用这些工具让我的手机向我询问蓝牙权限:
ActivityCompat
ContextCompat
PackageManager
onRequestPermissionsResult
但经过多个小时的测试后没有运气。 我什至尝试使用 GitHub 上的库为我请求“简单”权限,但没有成功:
https://github。 com/googlesamples/easypermissions https://github.com/guolindev/PermissionX
我尝试降低目标 SDK 版本,所以我不这样做不需要要求用户输入,但“AndroidX”给了我一个错误,告诉我它与较低的 SDK 不兼容。
如果您有一个基本的工作蓝牙应用程序 java 代码,这将对我有很大帮助,这样我就可以弄清楚如何编写我自己的应用程序。
I need an example java code of Bluetooth permissions. Android 12.
I know that I have to put this in the AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH"/>
From my research I think I have to use these tools to get my phone to ask me for Bluetooth permissions:
ActivityCompat
ContextCompat
PackageManager
onRequestPermissionsResult
But no luck after many hours of tests.
I even tried using libraries from GitHub to ask for "easy" permissions for me but no luck:
https://github.com/googlesamples/easypermissions
https://github.com/guolindev/PermissionX
I tried lowering my target SDK version so I don't need to ask for the user entry but "AndroidX" gave me an error telling that its not compatible with lower SDK's.
It would help me a ton if you have a basic working Bluetooth app java code so I can figure out how to code my own app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于Android 12上新的蓝牙权限,您需要这些权限:
您可以参考此博客文章了解更多详细信息。
For the new Bluetooth permissions on Android 12, you need these permissions:
You can refer to this blog post for more details.
对于 Android 12 上的蓝牙权限,您需要这些权限,具体取决于您的使用情况:
在您的 Activity 中,您可以添加此权限来检查是否允许:
要了解更多信息,您可以检查 文档。
For bluetooth permission on Android 12, you need these permission, depend on your usage:
In your activity, you can add this to check the permission is allowed or not:
To understand more, you can check the documentation.