Search in sources :

Example 11 with CanceledException

use of android.app.PendingIntent.CanceledException in project AndroidChromium by JackyAndroid.

the class FirstRunActivity method sendPendingIntentIfNecessary.

/**
     * Sends the PendingIntent included with the CHROME_LAUNCH_INTENT extra if it exists.
     * @param complete Whether first run completed successfully.
     */
protected void sendPendingIntentIfNecessary(final boolean complete) {
    PendingIntent pendingIntent = IntentUtils.safeGetParcelableExtra(getIntent(), EXTRA_CHROME_LAUNCH_INTENT);
    if (pendingIntent == null)
        return;
    Intent extraDataIntent = new Intent();
    extraDataIntent.putExtra(FirstRunActivity.EXTRA_FIRST_RUN_ACTIVITY_RESULT, true);
    extraDataIntent.putExtra(FirstRunActivity.EXTRA_FIRST_RUN_COMPLETE, complete);
    try {
        // After the PendingIntent has been sent, send a first run callback to custom tabs if
        // necessary.
        PendingIntent.OnFinished onFinished = new PendingIntent.OnFinished() {

            @Override
            public void onSendFinished(PendingIntent pendingIntent, Intent intent, int resultCode, String resultData, Bundle resultExtras) {
                if (ChromeLauncherActivity.isCustomTabIntent(intent)) {
                    CustomTabsConnection.getInstance(getApplication()).sendFirstRunCallbackIfNecessary(intent, complete);
                }
            }
        };
        // Use the PendingIntent to send the intent that originally launched Chrome. The intent
        // will go back to the ChromeLauncherActivity, which will route it accordingly.
        pendingIntent.send(this, complete ? Activity.RESULT_OK : Activity.RESULT_CANCELED, extraDataIntent, onFinished, null);
    } catch (CanceledException e) {
        Log.e(TAG, "Unable to send PendingIntent.", e);
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 12 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 13 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 14 with CanceledException

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

the class CdmaSMSDispatcher method handleCdmaStatusReport.

private void handleCdmaStatusReport(SmsMessage sms) {
    for (int i = 0, count = deliveryPendingList.size(); i < count; i++) {
        SmsTracker tracker = deliveryPendingList.get(i);
        if (tracker.mMessageRef == sms.messageRef) {
            // Found it.  Remove from list and broadcast.
            deliveryPendingList.remove(i);
            PendingIntent intent = tracker.mDeliveryIntent;
            Intent fillIn = new Intent();
            fillIn.putExtra("pdu", sms.getPdu());
            fillIn.putExtra("format", android.telephony.SmsMessage.FORMAT_3GPP2);
            try {
                intent.send(mContext, Activity.RESULT_OK, fillIn);
            } catch (CanceledException ex) {
            }
            // Only expect to see one tracker matching this message.
            break;
        }
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 15 with CanceledException

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

the class SMSDispatcher method handleMessage.

/**
     * Handles events coming from the phone stack. Overridden from handler.
     *
     * @param msg the message to handle
     */
@Override
public void handleMessage(Message msg) {
    AsyncResult ar;
    switch(msg.what) {
        case EVENT_NEW_SMS:
            // A new SMS has been received by the device
            if (false) {
                Log.d(TAG, "New SMS Message Received");
            }
            SmsMessage sms;
            ar = (AsyncResult) msg.obj;
            if (ar.exception != null) {
                Log.e(TAG, "Exception processing incoming SMS. Exception:" + ar.exception);
                return;
            }
            sms = (SmsMessage) ar.result;
            try {
                int result = dispatchMessage(sms.mWrappedSmsMessage);
                if (result != Activity.RESULT_OK) {
                    // RESULT_OK means that message was broadcast for app(s) to handle.
                    // Any other result, we should ack here.
                    boolean handled = (result == Intents.RESULT_SMS_HANDLED);
                    notifyAndAcknowledgeLastIncomingSms(handled, result, null);
                }
            } catch (RuntimeException ex) {
                Log.e(TAG, "Exception dispatching message", ex);
                notifyAndAcknowledgeLastIncomingSms(false, Intents.RESULT_SMS_GENERIC_ERROR, null);
            }
            break;
        case EVENT_SEND_SMS_COMPLETE:
            // An outbound SMS has been successfully transferred, or failed.
            handleSendComplete((AsyncResult) msg.obj);
            break;
        case EVENT_SEND_RETRY:
            sendSms((SmsTracker) msg.obj);
            break;
        case EVENT_POST_ALERT:
            handleReachSentLimit((SmsTracker) (msg.obj));
            break;
        case EVENT_ALERT_TIMEOUT:
            ((AlertDialog) (msg.obj)).dismiss();
            msg.obj = null;
            if (mSTrackers.isEmpty() == false) {
                try {
                    SmsTracker sTracker = mSTrackers.remove(0);
                    sTracker.mSentIntent.send(RESULT_ERROR_LIMIT_EXCEEDED);
                } catch (CanceledException ex) {
                    Log.e(TAG, "failed to send back RESULT_ERROR_LIMIT_EXCEEDED");
                }
            }
            if (false) {
                Log.d(TAG, "EVENT_ALERT_TIMEOUT, message stop sending");
            }
            break;
        case EVENT_SEND_CONFIRMED_SMS:
            if (mSTrackers.isEmpty() == false) {
                SmsTracker sTracker = mSTrackers.remove(mSTrackers.size() - 1);
                if (sTracker.isMultipart()) {
                    sendMultipartSms(sTracker);
                } else {
                    sendSms(sTracker);
                }
                removeMessages(EVENT_ALERT_TIMEOUT, msg.obj);
            }
            break;
        case EVENT_STOP_SENDING:
            if (mSTrackers.isEmpty() == false) {
                // Remove the latest one.
                try {
                    SmsTracker sTracker = mSTrackers.remove(mSTrackers.size() - 1);
                    sTracker.mSentIntent.send(RESULT_ERROR_LIMIT_EXCEEDED);
                } catch (CanceledException ex) {
                    Log.e(TAG, "failed to send back RESULT_ERROR_LIMIT_EXCEEDED");
                }
                removeMessages(EVENT_ALERT_TIMEOUT, msg.obj);
            }
            break;
    }
}
Also used : AlertDialog(android.app.AlertDialog) CanceledException(android.app.PendingIntent.CanceledException) SmsMessage(android.telephony.SmsMessage) AsyncResult(android.os.AsyncResult)

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