[英]Need BLUETOOTH permission : i don't have permission in some intent Android Studio
I am trying to create an app with a MainActivity that opens other activities.我正在尝试创建一个带有打开其他活动的 MainActivity 的应用程序。 When I use bluetooth for activities other than the Main, it gives me this kind of error.当我将蓝牙用于 Main 以外的活动时,它给了我这种错误。 While in my MainActivity this is not a problem.在我的 MainActivity 中,这不是问题。
It tells me that I don't have the permissions:它告诉我我没有权限:
2022-01-07 18:50:38.881 9466-9466/com.example.myapplication_dynahers E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication_dynahers, PID: 9466
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication_dynahers/com.example.myapplication_dynahers.Calibration_Activity}: java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10446 nor current process has android.permission.BLUETOOTH.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10446 nor current process has android.permission.BLUETOOTH.
while my Manifest.xml specifies the permissions:而我的 Manifest.xml 指定权限:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication_dynahers">
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BlUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication_DynaHERS">
<activity
android:name=".Active_Bluetooth_Activity"
android:exported="true" />
<activity
android:name=".Reset_Force_Activity"
android:exported="true" />
<activity
android:name=".Calibration_Activity"
android:exported="true" />
<activity
android:name=".Graph_Activity"
android:exported="true" />
<activity
android:name=".Using_Version_Activity"
android:exported="true" />
<activity
android:name=".Modify_Interval_Activity"
android:exported="true"
android:screenOrientation="portrait" />
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where could the problem come from?问题可能来自哪里?
Here is my error: I actually put the correct permissions in the Manifest (I may be missing the permission for the location because it is possible to locate a device with bluetooth), but what I forgot to do is check the permissions in the code.这是我的错误:我实际上在清单中放置了正确的权限(我可能缺少该位置的权限,因为可以找到带有蓝牙的设备),但我忘记做的是检查代码中的权限。 This should solve my problem.这应该可以解决我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.