View Confirmation recharge billing Dialog when send SMS

前端 未结 1 1104
终归单人心
终归单人心 2021-01-07 00:47

In the following Code to send SMS using SMS Manager:

SmsManager smsManager = SmsManager.getDefault();                                                      
sm         


        
相关标签:
1条回答
  • 2021-01-07 01:27

    You will find that you can't detect status if click Send or Cancel as long as you read the corresponding source code.

    "The default behavior for sending a message to a premium SMS short code (or suspected premium SMS number) is to ask the user for confirmation. Enable the user to set a default policy ("remember this choice" checkbox) to always/never allow the app to send SMS to premium short codes in the future. The policy can be changed by the Settings app in the app info screen." See here for details

    The dialog is defined in src/java/com/android/internal/telephony/SMSDispatcher.java

     /**
    * Post an alert when SMS needs confirmation due to excessive usage.
    * @param tracker an SmsTracker for the current message.
    */
    protected void handleReachSentLimit(SmsTracker tracker) {
        if (denyIfQueueLimitReached(tracker)) {
            return; // queue limit reached; error was returned to caller
        }
        CharSequence appLabel = getAppLabel(tracker.mAppInfo.packageName);
        Resources r = Resources.getSystem();
        Spanned messageText = Html.fromHtml(r.getString(R.string.sms_control_message, appLabel));
        ConfirmDialogListener listener = new ConfirmDialogListener(tracker);
        AlertDialog d = new AlertDialog.Builder(mContext)
               .setTitle(R.string.sms_control_title)
               .setIcon(R.drawable.stat_sys_warning)
               .setMessage(messageText)
               .setPositiveButton(r.getString(R.string.sms_control_yes), listener)
               .setNegativeButton(r.getString(R.string.sms_control_no), listener)
               .setOnCancelListener(listener)
               .create();
       d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
       d.show();
      }
    

    And the Callbacks of negative and positive button:

     /**
    * Dialog listener for SMS confirmation dialog.
    */
    private final class ConfirmDialogListener
    implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener,
    CompoundButton.OnCheckedChangeListener {
        private final SmsTracker mTracker;
        private Button mPositiveButton;
        private Button mNegativeButton;
        private boolean mRememberChoice; // default is unchecked
        ConfirmDialogListener(SmsTracker tracker) {
           mTracker = tracker;
        }
        void setPositiveButton(Button button) {
           mPositiveButton = button;
        }
        void setNegativeButton(Button button) {
          mNegativeButton = button;
        }
    @Override
        public void onClick(DialogInterface dialog, int which) {
    // Always set the SMS permission so that Settings will show a permission setting
    // for the app (it won't be shown until after the app tries to send to a short code).
          int newSmsPermission = SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ASK_USER;
          if (which == DialogInterface.BUTTON_POSITIVE) {
             Log.d(TAG, "CONFIRM sending SMS");
    // XXX this is lossy- apps can have more than one signature
             EventLog.writeEvent(EventLogTags.SMS_SENT_BY_USER,
             mTracker.mAppInfo.signatures[0].toCharsString());
             sendMessage(obtainMessage(EVENT_SEND_CONFIRMED_SMS, mTracker));
             if (mRememberChoice) {
                 newSmsPermission = SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW;
             }
             } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                 Log.d(TAG, "DENY sending SMS");
    // XXX this is lossy- apps can have more than one signature
            EventLog.writeEvent(EventLogTags.SMS_DENIED_BY_USER,
                mTracker.mAppInfo.signatures[0].toCharsString());
                sendMessage(obtainMessage(EVENT_STOP_SENDING, mTracker));
            if (mRememberChoice) {
                newSmsPermission = SmsUsageMonitor.PREMIUM_SMS_PERMISSION_NEVER_ALLOW;
            }
        }
           setPremiumSmsPermission(mTracker.mAppInfo.packageName, newSmsPermission);
    }
    

    When you click the Send or Cancel button on the dialog, it will send a message to its handler in its thread. But it seems that there is no way for you to capturing the click event.

    0 讨论(0)
提交回复
热议问题