即使我已声明,Android权限也不起作用

编程入门 行业动态 更新时间:2024-10-09 11:24:08
本文介绍了即使我已声明,Android权限也不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写代码以从Android应用发送短信,但是当我尝试发送短信时,它会将错误发送给我:

I'm trying to write code to send an SMS from an Android app, but when I try to send the SMS it sends me back the error:

09-17 18:37:29.974 12847-12847/**.**.****E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: **.**.****, PID: 12847 java.lang.SecurityException: Sending SMS message: uid 10092 does not have android.permission.SEND_SMS. at android.os.Parcel.readException(Parcel.java:1599) at android.os.Parcel.readException(Parcel.java:1552) at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:768) at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:310) at android.telephony.SmsManager.sendTextMessage(SmsManager.java:293) at **.**.****.MainActivity$3.onClick(MainActivity.java:70) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我检查过但我在清单中有权限,如下所示:

I checked but I have the permissions in the manifest, as follows:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.SEND_SMS"/> <uses-feature android:name="android.hardware.telephony" android:required="true"/> <application android:exported="true" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>

我搜索了互联网但是所有错误是关于< uses-permission /> 的语法,你能帮我吗?

I searched the internet but all the errors were about the <uses-permission/> syntax, could you help me please?

推荐答案

(以下内容摘自我的博客文章)

现在没有得到你的许可的重要原因是您的项目的 targetSdkVersion 为23或更高,而您请求的权限是危险的。在Android 6.0中,这包括:

The big reason for not getting your permission nowadays is because your project has a targetSdkVersion of 23 or higher, and the permission that you are requesting is "dangerous". In Android 6.0, this includes:

  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ADD_VOICEMAIL
  • BODY_SENSORS
  • CALL_PHONE
  • CAMERA
  • GET_ACCOUNTS
  • PROCESS_OUTGOING_CALLS
  • READ_CALENDAR
  • READ_CALL_LOG
  • READ_CELL_BROADCASTS
  • READ_CONTACTS
  • READ_EXTERNAL_STORAGE
  • READ_PHONE_STATE
  • READ_SMS
  • RECEIVE_MMS
  • RECEIVE_SMS
  • RECEIVE_WAP_PUSH
  • RECORD_AUDIO
  • SEND_SMS
  • USE_SIP
  • WRITE_CALENDAR
  • WRITE_CALL_LOG
  • WRITE_CONTACTS
  • WRITE_EXTERNAL_STORAGE
  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ADD_VOICEMAIL
  • BODY_SENSORS
  • CALL_PHONE
  • CAMERA
  • GET_ACCOUNTS
  • PROCESS_OUTGOING_CALLS
  • READ_CALENDAR
  • READ_CALL_LOG
  • READ_CELL_BROADCASTS
  • READ_CONTACTS
  • READ_EXTERNAL_STORAGE
  • READ_PHONE_STATE
  • READ_SMS
  • RECEIVE_MMS
  • RECEIVE_SMS
  • RECEIVE_WAP_PUSH
  • RECORD_AUDIO
  • SEND_SMS
  • USE_SIP
  • WRITE_CALENDAR
  • WRITE_CALL_LOG
  • WRITE_CONTACTS
  • WRITE_EXTERNAL_STORAGE

对于这些权限,您的 targetSdkVersion 23+不仅如此app 需要有< uses-permission> 元素,但是你还需要才能在运行时询问这些权限Android 6.0+ 设备上的用户,使用 checkSelfPermission()和 requestPermissions()。

For these permissions, not only does your targetSdkVersion 23+ app need to have the <uses-permission> element(s), but you also have to ask for those permissions at runtime from the user on Android 6.0+ devices, using methods like checkSelfPermission() and requestPermissions().

作为临时解决方法,请将 targetSdkVersion 降至23以下。

As a temporary workaround, drop your targetSdkVersion below 23.

但是,最终,您有理由希望 targetSdkVersion 为23或更高。那时,您需要来调整您的应用程序以使用新的运行时权限系统。 Android文档有 专门讨论此主题的页面。

However, eventually, you will have some reason to want your targetSdkVersion to be 23 or higher. At that time, you will need to adjust your app to use the new runtime permission system. The Android documentation has a page dedicated to this topic.

更多推荐

即使我已声明,Android权限也不起作用

本文发布于:2023-10-26 06:52:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也不   我已   权限   声明   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!