簡體   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