我收到此错误:
java.lang.SecurityException:正在发送SMS消息:uid 10282没有android.permission.SEND_SMS。
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.appidea">
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<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>
这是我的按钮的代码,因此当按下按钮时,它会发送文本消息:
Button button2 = (Button) findViewById(R.id.text);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String messageToSend = "this is a text";
String number = "XXXX";
SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
}
});