Search in sources :

Example 21 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 22 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 23 with CanceledException

use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.

the class ShadowLocationManager method setProviderEnabled.

public void setProviderEnabled(String provider, boolean isEnabled, List<Criteria> criteria) {
    LocationProviderEntry providerEntry = providersEnabled.get(provider);
    if (providerEntry == null) {
        providerEntry = new LocationProviderEntry();
    }
    providerEntry.enabled = isEnabled;
    providerEntry.criteria = criteria;
    providersEnabled.put(provider, providerEntry);
    List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners());
    for (LocationListener locationUpdateListener : locationUpdateListeners) {
        if (isEnabled) {
            locationUpdateListener.onProviderEnabled(provider);
        } else {
            locationUpdateListener.onProviderDisabled(provider);
        }
    }
    // Send intent to notify about provider status
    final Intent intent = new Intent();
    intent.putExtra(LocationManager.KEY_PROVIDER_ENABLED, isEnabled);
    ShadowApplication.getInstance().sendBroadcast(intent);
    Set<PendingIntent> requestLocationUdpatePendingIntentSet = requestLocationUdpateCriteriaPendingIntents.keySet();
    for (PendingIntent requestLocationUdpatePendingIntent : requestLocationUdpatePendingIntentSet) {
        try {
            requestLocationUdpatePendingIntent.send();
        } catch (CanceledException e) {
            requestLocationUdpateCriteriaPendingIntents.remove(requestLocationUdpatePendingIntent);
        }
    }
    // if this provider gets disabled and it was the best active provider, then it's not anymore
    if (provider.equals(bestEnabledProvider) && !isEnabled) {
        bestEnabledProvider = null;
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) LocationListener(android.location.LocationListener) ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 24 with CanceledException

use of android.app.PendingIntent.CanceledException in project OneSignal-Android-SDK by OneSignal.

the class PushRegistratorGPS method ShowUpdateGPSDialog.

private void ShowUpdateGPSDialog() {
    OSUtils.runOnMainUIThread(new Runnable() {

        @Override
        public void run() {
            final Activity activity = ActivityLifecycleHandler.curActivity;
            if (activity == null || OneSignal.mInitBuilder.mDisableGmsMissingPrompt)
                return;
            String alertBodyText = getResourceString(activity, "onesignal_gms_missing_alert_text", "To receive push notifications please press 'Update' to enable 'Google Play services'.");
            String alertButtonUpdate = getResourceString(activity, "onesignal_gms_missing_alert_button_update", "Update");
            String alertButtonSkip = getResourceString(activity, "onesignal_gms_missing_alert_button_skip", "Skip");
            String alertButtonClose = getResourceString(activity, "onesignal_gms_missing_alert_button_close", "Close");
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setMessage(alertBodyText).setPositiveButton(alertButtonUpdate, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(appContext);
                        GooglePlayServicesUtil.getErrorPendingIntent(resultCode, activity, 0).send();
                    } catch (CanceledException e) {
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            }).setNegativeButton(alertButtonSkip, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final SharedPreferences prefs = OneSignal.getGcmPreferences(activity);
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putBoolean("GT_DO_NOT_SHOW_MISSING_GPS", true);
                    editor.commit();
                }
            }).setNeutralButton(alertButtonClose, null).create().show();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) CanceledException(android.app.PendingIntent.CanceledException) DialogInterface(android.content.DialogInterface) SharedPreferences(android.content.SharedPreferences) Activity(android.app.Activity) OSUtils.getResourceString(com.onesignal.OSUtils.getResourceString) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 25 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)33 PendingIntent (android.app.PendingIntent)26 Intent (android.content.Intent)26 AlertDialog (android.app.AlertDialog)3 Bundle (android.os.Bundle)3 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)3 KeyEvent (android.view.KeyEvent)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 AsyncResult (android.os.AsyncResult)2 RecognizerIntent (android.speech.RecognizerIntent)2 SmsMessage (android.telephony.SmsMessage)2 ArrayList (java.util.ArrayList)2 NonNull (android.annotation.NonNull)1 ActivityThread (android.app.ActivityThread)1 FLAG_CANCEL_CURRENT (android.app.PendingIntent.FLAG_CANCEL_CURRENT)1 FLAG_IMMUTABLE (android.app.PendingIntent.FLAG_IMMUTABLE)1 FLAG_NO_CREATE (android.app.PendingIntent.FLAG_NO_CREATE)1 FLAG_ONE_SHOT (android.app.PendingIntent.FLAG_ONE_SHOT)1 FLAG_UPDATE_CURRENT (android.app.PendingIntent.FLAG_UPDATE_CURRENT)1