我没有收到任何短信,即使它显示短信发送



这是我从应用程序发送短信的代码:

protected void send() {
String no = mobileno.getText().toString();
String msg = message.getText().toString();
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, null, null);
Toast.makeText(getApplicationContext(), "sms sent", Toast.LENGTH_LONG).show();
}

activity.xml的代码是:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.spinnerex">
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_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>

它显示短信已发送,但我没有收到任何短信。它显示没有错误,但短信没有收到。

您是否为用户实现了权限请求?您必须申请使用SmsManager的权限。

如何在我的短信管理员中添加权限

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.SEND_SMS},1);

但这种方式是最糟糕的。您必须直接询问用户。你可以用谷歌搜索它。为了测试是否有问题,你可以在设置->你的应用程序设置->应用程序权限中手动授予它。

作为一种选择,您可以将其用作参考。

此外,可能还有助于Android短信管理器不发送短信

最新更新