简体   繁体   中英

uid does not have android.permission.SEND_SMS

I'm trying to send a message (SMS) from one emulator to another:

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="eheio.com.exo2">

    <uses-permission android:name="android.permission.SEND_SMS"/>


    <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/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Send message method:

public void sendMessage(View view) {
        EditText number = findViewById(R.id.number);
        EditText message = findViewById(R.id.message);
        try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(number.getText().toString(), null, message.getText().toString(), null, null);
            Toast.makeText(getApplicationContext(), "SMS Sent!", Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "SMS failed, please try again later!", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }

I'm getting the following exception:

java.lang.SecurityException: Sending SMS message: uid 10082 does not have android.permission.SEND_SMS.

For starters, you can inspect what permissions are granted to your apps by doing:

adb shell dumpsys package <your package>

and you'll see something like:

grantedPermissions:
  android.permission.MANAGE_ACCOUNTS
  android.permission.WRITE_SYNC_SETTINGS
  android.permission.RECEIVE_BOOT_COMPLETED

The android.permission.SEND_SMS permission is dangerous protection level. That means as of API 23 you need to prompt the user to accept the permission. It's not enough to declare its use in the manifest. You can read about that here: https://developer.android.com/guide/topics/permissions/overview#dangerous-permission-prompt

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM