I am trying to create an app with a MainActivity that opens other activities. When I use bluetooth for activities other than the Main, it gives me this kind of error. While in my MainActivity this is not a problem.
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 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.