首页 > 解决方案 > 即使显示已发送短信,我也没有收到任何短信

问题描述

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

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>

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

标签: androidsms

解决方案


您是否为用户实施了权限请求?您必须获得使用 SmsManager 的许可。

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

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

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

作为一个选项,您可以将此作为参考。

此外,Android 短信管理器不发送短信也可能会有所帮助


推荐阅读