gpt4 book ai didi

java - uid 没有 android.permission.SEND_SMS

转载 作者:行者123 更新时间:2023-12-02 01:52:30 30 4
gpt4 key购买 nike

我正在尝试从一个模拟器向另一个模拟器发送消息 (SMS):

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>

发送消息方法:

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();
}
}

我遇到以下异常:

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

最佳答案

对于初学者,您可以通过执行以下操作来检查授予您的应用的权限:

adb shell dumpsys package <your package>

你会看到类似的内容:

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

android.permission.SEND_SMS 权限为危险 保护级别。这意味着从 API 23 开始,您需要提示用户接受权限。在 list 中声明其用途是不够的。您可以在这里阅读相关内容: https://developer.android.com/guide/topics/permissions/overview#dangerous-permission-prompt

关于java - uid 没有 android.permission.SEND_SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52788243/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com