【问题标题】:I am not getting any SMS even after it shows SMS sent [duplicate]即使显示已发送短信,我也没有收到任何短信[重复]
【发布时间】:2020-03-10 16:40:04
【问题描述】:

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

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>

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

【问题讨论】:

标签: android sms


【解决方案1】:

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

how to add permission in my sms manager

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

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

作为一个选项,您可以使用this 作为参考。

另外,可能也有帮助Android sms manager not sending sms

【讨论】:

    猜你喜欢
    • 2012-05-25
    • 2017-02-24
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    相关资源
    最近更新 更多