What if it doesn't work even if I add a permission on Android?

Asked 1 years ago, Updated 1 years ago, 77 views

I'd like to send SMS from Android. If I send sms, the following error occurs.

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 thought it was because of the permission, so I gave the permission as below, but an error occurs.

<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-feature android:name="andrdoi.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>

I searched on the Internet, but I don't know why. Is it because of this? Help me.

android android-permissions

2022-09-22 21:33

1 Answers

Because the targetSdkVersion is 23 or higher, and the required permission is a "risk" rating. Starting from Android 6.0, the following permissions must be approved at runtime.

of this permission is I don't need this in more than 23 targetsdkversion. But in Android devices more than 6.0 checkselfpermission () going to authorise the permission to me () Using the programming offer to come to you.

This process can be a little tricky at first, so if you want to put out the urgent fire, you can lower the targetSdkVersion below 23.

If not, please refer to the topic about runtime permission in Android documentation.


2022-09-22 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.