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

问题描述 投票:0回答:1

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

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>

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

android sms
1个回答
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也可能有用

© www.soinside.com 2019 - 2024. All rights reserved.