繁体   English   中英

在 Oppo 手机上以编程方式发送短信

[英]Send SMS programmatically on Oppo phones

我的 android 应用程序以编程方式发送 SMS(通常由推送消息触发),并在许多 Android 版本和设备上按预期工作。 然而,在新的 Oppo 手机型号 CPH1851 上,我看到一个通知弹出窗口说:

“[应用名称] 将向 [电话号码] 发送短信”

(其中 [app name] 是我的应用程序的名称,[phone number] 是应用程序向其发送短信的号码

在此处输入图片说明

通知有一个“发送”按钮和一个“取消”按钮(后者带有递减计时器)

显然,这似乎是对 Android 安全性的又一次误导尝试,没有考虑碎片化和用户体验,只是想解决它。

谢谢您的帮助

请尝试以下代码并添加 SEND_SMS 权限。

try {
            SmsManager smsManager = SmsManager.getDefault();

            ArrayList<String> parts = smsManager.divideMessage(sb.toString());
            //smsManager.sendTextMessage(phoneNumber, null, message, null, null);
            smsManager.sendMultipartTextMessage(phone, null, parts,
                    null, null);
            Toast.makeText(activity, "Send Message Successfully ", Toast.LENGTH_SHORT).show();

        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "SMS Failed !", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }

下面的代码为我在 Oppo 手机中炒菜试试这个

SmsManager sms = SmsManager.getDefault();
        List<String> messages = sms.divideMessage(message);
        for (String msg : messages) {

            PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new Intent("SMS_SENT"), 0);
            PendingIntent deliveredIntent = PendingIntent.getBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0);
            sms.sendTextMessage(phone, null, msg, sentIntent, deliveredIntent);
            Toast.makeText(activity, "Send Message Successfully", Toast.LENGTH_SHORT).show();

        }

Oppo的定制版Android(称为ColorOS)是造成这种麻烦的原因。

Settings/Security/Permissions/Send SMS 显示应用程序是否“允许”发送短信(“询问”和“禁止”是其他选项)。 将此设置为“允许”会使问题在一个 Oppo 型号上消失。 但不是在另一个。

所以另一个选项是启用开发者选项,并在列表的最底部打开“禁用权限监控”(这似乎关闭了所有的 ColorOS 权限监控,但不影响基本的 Android 权限)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM