Search in sources :

Example 16 with CanceledException

use of android.app.PendingIntent.CanceledException in project XobotOS by xamarin.

the class SMSDispatcher method handleReachSentLimit.

/**
     * Post an alert while SMS needs user confirm.
     *
     * An SmsTracker for the current message.
     */
protected void handleReachSentLimit(SmsTracker tracker) {
    if (mSTrackers.size() >= MO_MSG_QUEUE_LIMIT) {
        // Deny the sending when the queue limit is reached.
        try {
            tracker.mSentIntent.send(RESULT_ERROR_LIMIT_EXCEEDED);
        } catch (CanceledException ex) {
            Log.e(TAG, "failed to send back RESULT_ERROR_LIMIT_EXCEEDED");
        }
        return;
    }
    Resources r = Resources.getSystem();
    String appName = getAppNameByIntent(tracker.mSentIntent);
    AlertDialog d = new AlertDialog.Builder(mContext).setTitle(r.getString(R.string.sms_control_title)).setMessage(appName + " " + r.getString(R.string.sms_control_message)).setPositiveButton(r.getString(R.string.sms_control_yes), mListener).setNegativeButton(r.getString(R.string.sms_control_no), mListener).create();
    d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    d.show();
    mSTrackers.add(tracker);
    sendMessageDelayed(obtainMessage(EVENT_ALERT_TIMEOUT, d), DEFAULT_SMS_TIMEOUT);
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) AlertDialog(android.app.AlertDialog) Resources(android.content.res.Resources)

Example 17 with CanceledException

use of android.app.PendingIntent.CanceledException in project XobotOS by xamarin.

the class SMSDispatcher method handleSendComplete.

/**
     * Called when SMS send completes. Broadcasts a sentIntent on success.
     * On failure, either sets up retries or broadcasts a sentIntent with
     * the failure in the result code.
     *
     * @param ar AsyncResult passed into the message handler.  ar.result should
     *           an SmsResponse instance if send was successful.  ar.userObj
     *           should be an SmsTracker instance.
     */
protected void handleSendComplete(AsyncResult ar) {
    SmsTracker tracker = (SmsTracker) ar.userObj;
    PendingIntent sentIntent = tracker.mSentIntent;
    if (ar.exception == null) {
        if (false) {
            Log.d(TAG, "SMS send complete. Broadcasting " + "intent: " + sentIntent);
        }
        if (tracker.mDeliveryIntent != null) {
            // Expecting a status report.  Add it to the list.
            int messageRef = ((SmsResponse) ar.result).messageRef;
            tracker.mMessageRef = messageRef;
            deliveryPendingList.add(tracker);
        }
        if (sentIntent != null) {
            try {
                if (mRemainingMessages > -1) {
                    mRemainingMessages--;
                }
                if (mRemainingMessages == 0) {
                    Intent sendNext = new Intent();
                    sendNext.putExtra(SEND_NEXT_MSG_EXTRA, true);
                    sentIntent.send(mContext, Activity.RESULT_OK, sendNext);
                } else {
                    sentIntent.send(Activity.RESULT_OK);
                }
            } catch (CanceledException ex) {
            }
        }
    } else {
        if (false) {
            Log.d(TAG, "SMS send failed");
        }
        int ss = mPhone.getServiceState().getState();
        if (ss != ServiceState.STATE_IN_SERVICE) {
            handleNotInService(ss, tracker);
        } else if ((((CommandException) (ar.exception)).getCommandError() == CommandException.Error.SMS_FAIL_RETRY) && tracker.mRetryCount < MAX_SEND_RETRIES) {
            // Retry after a delay if needed.
            // TODO: According to TS 23.040, 9.2.3.6, we should resend
            //       with the same TP-MR as the failed message, and
            //       TP-RD set to 1.  However, we don't have a means of
            //       knowing the MR for the failed message (EF_SMSstatus
            //       may or may not have the MR corresponding to this
            //       message, depending on the failure).  Also, in some
            //       implementations this retry is handled by the baseband.
            tracker.mRetryCount++;
            Message retryMsg = obtainMessage(EVENT_SEND_RETRY, tracker);
            sendMessageDelayed(retryMsg, SEND_RETRY_DELAY);
        } else if (tracker.mSentIntent != null) {
            int error = RESULT_ERROR_GENERIC_FAILURE;
            if (((CommandException) (ar.exception)).getCommandError() == CommandException.Error.FDN_CHECK_FAILURE) {
                error = RESULT_ERROR_FDN_CHECK_FAILURE;
            }
            // Done retrying; return an error to the app.
            try {
                Intent fillIn = new Intent();
                if (ar.result != null) {
                    fillIn.putExtra("errorCode", ((SmsResponse) ar.result).errorCode);
                }
                if (mRemainingMessages > -1) {
                    mRemainingMessages--;
                }
                if (mRemainingMessages == 0) {
                    fillIn.putExtra(SEND_NEXT_MSG_EXTRA, true);
                }
                tracker.mSentIntent.send(mContext, error, fillIn);
            } catch (CanceledException ex) {
            }
        }
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) SmsMessage(android.telephony.SmsMessage) Message(android.os.Message) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 18 with CanceledException

use of android.app.PendingIntent.CanceledException in project XobotOS by xamarin.

the class TransportControlView method sendMediaButtonClick.

private void sendMediaButtonClick(int keyCode) {
    if (mClientIntent == null) {
        // Shouldn't be possible because this view should be hidden in this case.
        Log.e(TAG, "sendMediaButtonClick(): No client is currently registered");
        return;
    }
    // use the registered PendingIntent that will be processed by the registered
    //    media button event receiver, which is the component of mClientIntent
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button down: " + e);
        e.printStackTrace();
    }
    keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
    intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button up: " + e);
        e.printStackTrace();
    }
}
Also used : KeyEvent(android.view.KeyEvent) CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 19 with CanceledException

use of android.app.PendingIntent.CanceledException in project android_frameworks_base by crdroidandroid.

the class ImeTile method handleClick.

@Override
public void handleClick() {
    mHost.collapsePanels();
    Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
    try {
        pendingIntent.send();
    } catch (CanceledException e) {
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

CanceledException (android.app.PendingIntent.CanceledException)19 PendingIntent (android.app.PendingIntent)16 Intent (android.content.Intent)16 AlertDialog (android.app.AlertDialog)3 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)3 KeyEvent (android.view.KeyEvent)3 Bundle (android.os.Bundle)2 RecognizerIntent (android.speech.RecognizerIntent)2 SmsMessage (android.telephony.SmsMessage)2 Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 LocationListener (android.location.LocationListener)1 AsyncResult (android.os.AsyncResult)1 Message (android.os.Message)1 OSUtils.getResourceString (com.onesignal.OSUtils.getResourceString)1 ArrayList (java.util.ArrayList)1 Tab (org.chromium.chrome.browser.tab.Tab)1