Example usage for android.app PendingIntent send

List of usage examples for android.app PendingIntent send

Introduction

In this page you can find the example usage for android.app PendingIntent send.

Prototype

public void send() throws CanceledException 

Source Link

Document

Perform the operation associated with this PendingIntent.

Usage

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

/**
 * Send a newly created intent to Scheduler to update notification and setup a new bell schedule for meditation.
 *
 * @param nextTargetTimeMillis/*from w ww . j a  v a2s  .com*/
 *         Millis to be given to Scheduler as now (or nextTargetTimeMillis from the perspective of the previous call)
 * @param meditationPeriod
 *         Zero: ramp-up, 1-(n-1): intermediate period, n: last period, n+1: beyond end
 */
public void updateBellScheduleForMeditation(long nextTargetTimeMillis, int meditationPeriod) {
    MindBell.logDebug(
            "Update bell schedule for meditation requested, nextTargetTimeMillis=" + nextTargetTimeMillis);
    PendingIntent sender = createSchedulerBroadcastIntent(false, nextTargetTimeMillis, meditationPeriod);
    try {
        sender.send();
    } catch (PendingIntent.CanceledException e) {
        Log.e(TAG, "Could not update bell schedule for meditation: " + e.getMessage(), e);
    }
}

From source file:org.mozilla.focus.fragment.BrowserFragment.java

private void initialiseCustomTabUi(final @NonNull View view) {
    final CustomTabConfig customTabConfig = BrowsingSession.getInstance().getCustomTabConfig();
    if (customTabConfig == null) {
        throw new IllegalStateException("Can't initialise custom tab UI for non custom-tab session");
    }//from w  w  w.ja v a 2  s . co  m

    // Unfortunately there's no simpler way to have the FAB only in normal-browser mode.
    // - ViewStub: requires splitting attributes for the FAB between the ViewStub, and actual FAB layout file.
    //             Moreover, the layout behaviour just doesn't work unless you set it programatically.
    // - View.GONE: doesn't work because the layout-behaviour makes the FAB visible again when scrolling.
    // - Adding at runtime: works, but then we need to use a separate layout file (and you need
    //   to set some attributes programatically, same as ViewStub).
    final View erase = view.findViewById(R.id.erase);
    final ViewGroup eraseContainer = (ViewGroup) erase.getParent();
    eraseContainer.removeView(erase);

    final View toolbar = view.findViewById(R.id.urlbar);
    if (customTabConfig.toolbarColor != null) {
        toolbar.setBackgroundColor(customTabConfig.toolbarColor);
    }

    final ImageView closeButton = (ImageView) view.findViewById(R.id.customtab_close);

    closeButton.setVisibility(View.VISIBLE);
    closeButton.setOnClickListener(this);

    if (customTabConfig.closeButtonIcon != null) {
        closeButton.setImageBitmap(customTabConfig.closeButtonIcon);
    } else {
        // Always set the icon in case it's been overridden by a previous CT invocation
        closeButton.setImageResource(R.drawable.ic_close);
    }

    if (customTabConfig.disableUrlbarHiding) {
        AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
        params.setScrollFlags(0);
    }

    if (customTabConfig.actionButtonConfig != null) {
        final ImageButton actionButton = (ImageButton) view.findViewById(R.id.customtab_actionbutton);
        actionButton.setVisibility(View.VISIBLE);

        actionButton.setImageBitmap(customTabConfig.actionButtonConfig.icon);
        actionButton.setContentDescription(customTabConfig.actionButtonConfig.description);

        final PendingIntent pendingIntent = customTabConfig.actionButtonConfig.pendingIntent;

        actionButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    pendingIntent.send();
                } catch (PendingIntent.CanceledException e) {
                    // There's really nothing we can do here...
                }
            }
        });
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void notificationChanged(AccessibilityEvent event) {
    try {//from www .j  av  a  2 s.c o m

        List<CharSequence> mCharSequences = event.getText();
        if (mCharSequences == null || mCharSequences.isEmpty())
            return;
        StringBuffer sb = new StringBuffer();
        for (CharSequence c : mCharSequences) {
            sb.append(c.toString());
        }
        if (!sb.toString().contains("?"))
            return;
        Parcelable mParcelable = event.getParcelableData();
        if (mParcelable != null && mParcelable instanceof Notification) {
            Notification mNotification = (Notification) mParcelable;
            PendingIntent mPendingIntent = mNotification.contentIntent;
            if (mPendingIntent == null)
                return;
            /**/
            mPendingIntent.send();
        }
    } catch (Exception e) {

    }
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager.java

@Override
public void onConnectionFailed(ConnectionResult result) {
    LOGD(TAG, "onConnectionFailed() reached, error code: " + result.getErrorCode() + ", reason: "
            + result.toString());//from  w w  w  . j a va  2  s  .  co m
    disconnectDevice(mDestroyOnDisconnect, false /* clearPersistentConnectionData */,
            false /* setDefaultRoute */);
    mConnectionSuspended = false;
    if (mMediaRouter != null) {
        mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
    }

    for (BaseCastConsumer consumer : mBaseCastConsumers) {
        consumer.onConnectionFailed(result);
    }

    PendingIntent pendingIntent = result.getResolution();
    if (pendingIntent != null) {
        try {
            pendingIntent.send();
        } catch (PendingIntent.CanceledException e) {
            LOGE(TAG, "Failed to show recovery from the recoverable error", e);
        }
    }
}

From source file:edu.mit.media.funf.probe.Probe.java

private void loadRequestsIntent(Intent currentIntent) {
    if (isRequestsIntent(currentIntent)) {
        Log.d(TAG, "Is requests intent.");
        requestsIntent = currentIntent;//w  w w  .j a va  2  s . c  o  m
    } else {
        // Attempt to grab pending intent and send Otherwise initialize requestsIntent
        Intent internalRunIntent = getRequestsIntent();
        PendingIntent selfLaunchingIntent = PendingIntent.getService(this, 0, internalRunIntent,
                PendingIntent.FLAG_NO_CREATE);
        if (selfLaunchingIntent == null) {
            requestsIntent = internalRunIntent;
        } else {
            try {
                Log.i(TAG, "Sending requests pending intent and waiting");
                selfLaunchingIntent.send();
                queueIntent(currentIntent, true);
                pauseQueueUntilIntentReceived(internalRunIntent, null);
            } catch (CanceledException e) {
                Log.e(TAG, "CANCELLED INTERNAL RUN INTENT");
                requestsIntent = internalRunIntent;
            }
        }
    }
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    setContentView(R.layout.mr_controller_material_dialog_b);

    // Remove the neutral button.
    findViewById(BUTTON_NEUTRAL_RES_ID).setVisibility(View.GONE);

    ClickListener listener = new ClickListener();

    mExpandableAreaLayout = (FrameLayout) findViewById(R.id.mr_expandable_area);
    mExpandableAreaLayout.setOnClickListener(new View.OnClickListener() {
        @Override// w  w  w .ja v a  2s.c  om
        public void onClick(View v) {
            dismiss();
        }
    });
    mDialogAreaLayout = (LinearLayout) findViewById(R.id.mr_dialog_area);
    mDialogAreaLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Eat unhandled touch events.
        }
    });
    int color = MediaRouterThemeHelper.getButtonTextColor(mContext);
    mDisconnectButton = (Button) findViewById(BUTTON_DISCONNECT_RES_ID);
    mDisconnectButton.setText(R.string.mr_controller_disconnect);
    mDisconnectButton.setTextColor(color);
    mDisconnectButton.setOnClickListener(listener);

    mStopCastingButton = (Button) findViewById(BUTTON_STOP_RES_ID);
    mStopCastingButton.setText(R.string.mr_controller_stop);
    mStopCastingButton.setTextColor(color);
    mStopCastingButton.setOnClickListener(listener);

    mRouteNameTextView = (TextView) findViewById(R.id.mr_name);
    mCloseButton = (ImageButton) findViewById(R.id.mr_close);
    mCloseButton.setOnClickListener(listener);
    mCustomControlLayout = (FrameLayout) findViewById(R.id.mr_custom_control);
    mDefaultControlLayout = (FrameLayout) findViewById(R.id.mr_default_control);

    // Start the session activity when a content item (album art, title or subtitle) is clicked.
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMediaController != null) {
                PendingIntent pi = mMediaController.getSessionActivity();
                if (pi != null) {
                    try {
                        pi.send();
                        dismiss();
                    } catch (PendingIntent.CanceledException e) {
                        Log.e(TAG, pi + " was not sent, it had been canceled.");
                    }
                }
            }
        }
    };
    mArtView = (ImageView) findViewById(R.id.mr_art);
    mArtView.setOnClickListener(onClickListener);
    findViewById(R.id.mr_control_title_container).setOnClickListener(onClickListener);

    mMediaMainControlLayout = (LinearLayout) findViewById(R.id.mr_media_main_control);
    mDividerView = findViewById(R.id.mr_control_divider);

    mPlaybackControlLayout = (RelativeLayout) findViewById(R.id.mr_playback_control);
    mTitleView = (TextView) findViewById(R.id.mr_control_title);
    mSubtitleView = (TextView) findViewById(R.id.mr_control_subtitle);
    mPlayPauseButton = (ImageButton) findViewById(R.id.mr_control_play_pause);
    mPlayPauseButton.setOnClickListener(listener);

    mVolumeControlLayout = (LinearLayout) findViewById(R.id.mr_volume_control);
    mVolumeControlLayout.setVisibility(View.GONE);
    mVolumeSlider = (SeekBar) findViewById(R.id.mr_volume_slider);
    mVolumeSlider.setTag(mRoute);
    mVolumeChangeListener = new VolumeChangeListener();
    mVolumeSlider.setOnSeekBarChangeListener(mVolumeChangeListener);

    mVolumeGroupList = (OverlayListView) findViewById(R.id.mr_volume_group_list);
    mGroupMemberRoutes = new ArrayList<MediaRouter.RouteInfo>();
    mVolumeGroupAdapter = new VolumeGroupAdapter(mContext, mGroupMemberRoutes);
    mVolumeGroupList.setAdapter(mVolumeGroupAdapter);
    mGroupMemberRoutesAnimatingWithBitmap = new HashSet<>();

    MediaRouterThemeHelper.setMediaControlsBackgroundColor(mContext, mMediaMainControlLayout, mVolumeGroupList,
            getGroup() != null);
    MediaRouterThemeHelper.setVolumeSliderColor(mContext, (MediaRouteVolumeSlider) mVolumeSlider,
            mMediaMainControlLayout);
    mVolumeSliderMap = new HashMap<>();
    mVolumeSliderMap.put(mRoute, mVolumeSlider);

    mGroupExpandCollapseButton = (MediaRouteExpandCollapseButton) findViewById(R.id.mr_group_expand_collapse);
    mGroupExpandCollapseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mIsGroupExpanded = !mIsGroupExpanded;
            if (mIsGroupExpanded) {
                mVolumeGroupList.setVisibility(View.VISIBLE);
            }
            loadInterpolator();
            updateLayoutHeight(true);
        }
    });
    loadInterpolator();
    mGroupListAnimationDurationMs = mContext.getResources()
            .getInteger(R.integer.mr_controller_volume_group_list_animation_duration_ms);
    mGroupListFadeInDurationMs = mContext.getResources()
            .getInteger(R.integer.mr_controller_volume_group_list_fade_in_duration_ms);
    mGroupListFadeOutDurationMs = mContext.getResources()
            .getInteger(R.integer.mr_controller_volume_group_list_fade_out_duration_ms);

    mCustomControlView = onCreateMediaControlView(savedInstanceState);
    if (mCustomControlView != null) {
        mCustomControlLayout.addView(mCustomControlView);
        mCustomControlLayout.setVisibility(View.VISIBLE);
    }
    mCreated = true;
    updateLayout();
}

From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    setContentView(R.layout.mr_controller_material_dialog_b);

    // Remove the neutral button.
    findViewById(BUTTON_NEUTRAL_RES_ID).setVisibility(View.GONE);

    ClickListener listener = new ClickListener();

    mExpandableAreaLayout = findViewById(R.id.mr_expandable_area);
    mExpandableAreaLayout.setOnClickListener(new View.OnClickListener() {
        @Override/*from   www  . java 2 s. c o  m*/
        public void onClick(View v) {
            dismiss();
        }
    });
    mDialogAreaLayout = findViewById(R.id.mr_dialog_area);
    mDialogAreaLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Eat unhandled touch events.
        }
    });
    int color = MediaRouterThemeHelper.getButtonTextColor(mContext);
    mDisconnectButton = findViewById(BUTTON_DISCONNECT_RES_ID);
    mDisconnectButton.setText(R.string.mr_controller_disconnect);
    mDisconnectButton.setTextColor(color);
    mDisconnectButton.setOnClickListener(listener);

    mStopCastingButton = findViewById(BUTTON_STOP_RES_ID);
    mStopCastingButton.setText(R.string.mr_controller_stop_casting);
    mStopCastingButton.setTextColor(color);
    mStopCastingButton.setOnClickListener(listener);

    mRouteNameTextView = findViewById(R.id.mr_name);
    mCloseButton = findViewById(R.id.mr_close);
    mCloseButton.setOnClickListener(listener);
    mCustomControlLayout = findViewById(R.id.mr_custom_control);
    mDefaultControlLayout = findViewById(R.id.mr_default_control);

    // Start the session activity when a content item (album art, title or subtitle) is clicked.
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMediaController != null) {
                PendingIntent pi = mMediaController.getSessionActivity();
                if (pi != null) {
                    try {
                        pi.send();
                        dismiss();
                    } catch (PendingIntent.CanceledException e) {
                        Log.e(TAG, pi + " was not sent, it had been canceled.");
                    }
                }
            }
        }
    };
    mArtView = findViewById(R.id.mr_art);
    mArtView.setOnClickListener(onClickListener);
    findViewById(R.id.mr_control_title_container).setOnClickListener(onClickListener);

    mMediaMainControlLayout = findViewById(R.id.mr_media_main_control);
    mDividerView = findViewById(R.id.mr_control_divider);

    mPlaybackControlLayout = findViewById(R.id.mr_playback_control);
    mTitleView = findViewById(R.id.mr_control_title);
    mSubtitleView = findViewById(R.id.mr_control_subtitle);
    mPlaybackControlButton = findViewById(R.id.mr_control_playback_ctrl);
    mPlaybackControlButton.setOnClickListener(listener);

    mVolumeControlLayout = findViewById(R.id.mr_volume_control);
    mVolumeControlLayout.setVisibility(View.GONE);
    mVolumeSlider = findViewById(R.id.mr_volume_slider);
    mVolumeSlider.setTag(mRoute);
    mVolumeChangeListener = new VolumeChangeListener();
    mVolumeSlider.setOnSeekBarChangeListener(mVolumeChangeListener);

    mVolumeGroupList = findViewById(R.id.mr_volume_group_list);
    mGroupMemberRoutes = new ArrayList<MediaRouter.RouteInfo>();
    mVolumeGroupAdapter = new VolumeGroupAdapter(mVolumeGroupList.getContext(), mGroupMemberRoutes);
    mVolumeGroupList.setAdapter(mVolumeGroupAdapter);
    mGroupMemberRoutesAnimatingWithBitmap = new HashSet<>();

    MediaRouterThemeHelper.setMediaControlsBackgroundColor(mContext, mMediaMainControlLayout, mVolumeGroupList,
            getGroup() != null);
    MediaRouterThemeHelper.setVolumeSliderColor(mContext, (MediaRouteVolumeSlider) mVolumeSlider,
            mMediaMainControlLayout);
    mVolumeSliderMap = new HashMap<>();
    mVolumeSliderMap.put(mRoute, mVolumeSlider);

    mGroupExpandCollapseButton = findViewById(R.id.mr_group_expand_collapse);
    mGroupExpandCollapseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mIsGroupExpanded = !mIsGroupExpanded;
            if (mIsGroupExpanded) {
                mVolumeGroupList.setVisibility(View.VISIBLE);
            }
            loadInterpolator();
            updateLayoutHeight(true);
        }
    });
    loadInterpolator();
    mGroupListAnimationDurationMs = mContext.getResources()
            .getInteger(R.integer.mr_controller_volume_group_list_animation_duration_ms);
    mGroupListFadeInDurationMs = mContext.getResources()
            .getInteger(R.integer.mr_controller_volume_group_list_fade_in_duration_ms);
    mGroupListFadeOutDurationMs = mContext.getResources()
            .getInteger(R.integer.mr_controller_volume_group_list_fade_out_duration_ms);

    mCustomControlView = onCreateMediaControlView(savedInstanceState);
    if (mCustomControlView != null) {
        mCustomControlLayout.addView(mCustomControlView);
        mCustomControlLayout.setVisibility(View.VISIBLE);
    }
    mCreated = true;
    updateLayout();
}

From source file:org.restcomm.android.sdk.RCDevice.java

/**
 * Internal service callback; not meant for application use
 * @param jobId the job Id that was used in the original request, so that we can correlate the two
 * @param peer the peer from which the call arrived
 * @param sdpOffer sdp offer sent by the peer
 * @param customHeaders any custom SIP headers sent by the peer
 *///w ww  .ja  v a 2  s.c om
public void onCallArrivedEvent(String jobId, String peer, String sdpOffer,
        HashMap<String, String> customHeaders) {
    RCLogger.i(TAG, "onCallArrivedEvent(): id: " + jobId + ", peer: " + peer);

    // filter out potential '<' and '>' and leave just the SIP URI
    String peerSipUri = peer.replaceAll("^<", "").replaceAll(">$", "");

    RCConnection connection = new RCConnection.Builder(true, RCConnection.ConnectionState.CONNECTING, this,
            signalingClient, audioManager).jobId(jobId).incomingCallSdp(sdpOffer).peer(peerSipUri)
                    .deviceAlreadyBusy(state == DeviceState.BUSY).customHeaders(customHeaders).build();

    // keep connection in the connections hashmap
    connections.put(jobId, connection);

    if (state == DeviceState.BUSY) {
        // If we are already talking disconnect the new call
        connection.reject();
        return;
    }

    state = DeviceState.BUSY;

    if (isAttached()) {
        audioManager.playRingingSound();
        // Service is attached to an activity, let's send the intent normally that will open the call activity
        callIntent.setAction(ACTION_INCOMING_CALL);
        callIntent.putExtra(RCDevice.EXTRA_DID, peerSipUri);
        callIntent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED,
                (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO));
        if (customHeaders != null) {
            callIntent.putExtra(RCDevice.EXTRA_CUSTOM_HEADERS, customHeaders);
        }
        //startActivity(callIntent);

        if (!this.parameters.containsKey(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)
                || !(Boolean) this.parameters.get(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)) {
            PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, callIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            try {
                pendingIntent.send();
            } catch (PendingIntent.CanceledException e) {
                throw new RuntimeException("Pending Intent cancelled", e);
            }
        } else {
            // ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS == true, we need to broadcast a separate intent, so that the Test Case is able to receive it.
            // For some reason PendingIntent is not received properly even when we construct a broadcast for it using getBroadcast()
            Intent testIntent = new Intent(RCDevice.ACTION_INCOMING_CALL); //, null, InstrumentationRegistry.getTargetContext(), IntegrationTests.class));
            testIntent.putExtra(RCDevice.EXTRA_DID, peerSipUri);
            sendBroadcast(testIntent);
        }
        // Phone state Intents to capture incoming phone call event
        sendQoSIncomingConnectionIntent(peerSipUri, connection);
    } else {
        onNotificationCall(connection, customHeaders);
    }
}

From source file:org.restcomm.android.sdk.RCDevice.java

/**
 * Internal signaling callback; not meant for application use
 * @param jobId the job Id that was used in the original request, so that we can correlate the two
 * @param peer the peer from which the text message arrived
 * @param messageText actual text of the incoming text message
 *///from  w ww. j  av  a  2 s.com
public void onMessageArrivedEvent(String jobId, String peer, String messageText) {
    RCLogger.i(TAG, "onMessageArrivedEvent(): id: " + jobId + ", peer: " + peer + ", text: " + messageText);
    // filter out potential '<' and '>' and leave just the SIP URI
    String peerSipUri = peer.replaceAll("^<", "").replaceAll(">$", "");

    //parameters.put(RCConnection.ParameterKeys.CONNECTION_PEER, from);

    if (messageIntent != null) {
        if (isAttached()) {
            audioManager.playMessageSound();

            messageIntent.setAction(ACTION_INCOMING_MESSAGE);
            messageIntent.putExtra(EXTRA_DID, peerSipUri);
            messageIntent.putExtra(EXTRA_MESSAGE_TEXT, messageText);
            //startActivity(messageIntent);

            if (!this.parameters.containsKey(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)
                    || !(Boolean) this.parameters.get(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)) {
                PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        messageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                try {
                    pendingIntent.send();
                } catch (PendingIntent.CanceledException e) {
                    throw new RuntimeException("Pending Intent cancelled", e);
                }
            } else {
                // ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS == true, we need to broadcast a separate intent, so that the Test Case is able to receive it.
                // For some reason PendingIntent is not received properly even when we construct a broadcast for it using getBroadcast()
                Intent testIntent = new Intent(RCDevice.ACTION_INCOMING_MESSAGE); //, null, InstrumentationRegistry.getTargetContext(), IntegrationTests.class));
                testIntent.putExtra(EXTRA_DID, peerSipUri);
                testIntent.putExtra(EXTRA_MESSAGE_TEXT, messageText);
                sendBroadcast(testIntent);
            }
        } else {
            if (messageTimeoutHandler == null) {
                messageTimeoutHandler = new Handler();
            }
            startRepeatingTask();

            //set timer again
            messageTimeOutInterval = messageTimeOutIntervalLimit;
            onNotificationMessage(peerSipUri, messageText);
        }
    } else {
        // messageIntent is null cannot really forward event to App, lets ignore with a warning
        RCLogger.w(TAG,
                "onMessageArrivedEvent(): Incoming text message event is discarded because Intent is missing for incoming text messages. "
                        + "To receive such event please initialize RCDevice with a RCDevice.ACTION_INCOMING_MESSAGE intent");
    }
}

From source file:org.restcomm.android.sdk.RCDevice.java

void onNotificationIntent(Intent intent) {
    String intentAction = intent.getAction();

    //if (!intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) {
    if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT)
            || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO)
            || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO)
            || intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE)
            || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) {
        // The user has acted on a call notification, let's cancel it
        String username = intent.getStringExtra(EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "");

        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(callNotifications.get(username));

        //callNotifications.remove(username);

        activeCallNotification = false;/*from  w  w w  .  j  a v a  2s .  c o  m*/
    }

    Intent actionIntent = null;
    /*
    if (intentAction.equals(ACTION_NOTIFICATION_CALL_OPEN)) {
       RCConnection connection = getLiveConnection();
       if (connection != null) {
    if (connection.isIncoming()) {
       callIntent.setAction(ACTION_INCOMING_CALL);
    }
    else {
       callIntent.setAction(ACTION_OUTGOING_CALL);
    }
    callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    // don't forget to copy the extras to callIntent
    callIntent.putExtras(intent);
    actionIntent = callIntent;
       }
    }
    */
    if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT)) {
        if (callIntent != null) {
            callIntent.setAction(ACTION_INCOMING_CALL);
            // don't forget to copy the extras to callIntent
            callIntent.putExtras(intent);
            actionIntent = callIntent;
        } else {
            Context context = getApplicationContext();
            PackageManager packageManager = context.getPackageManager();
            actionIntent = packageManager.getLaunchIntentForPackage(context.getPackageName());
        }

    } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO)) {
        callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_VIDEO);
        // don't forget to copy the extras
        callIntent.putExtras(intent);
        actionIntent = callIntent;
    } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO)) {
        callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_AUDIO);
        // don't forget to copy the extras
        callIntent.putExtras(intent);

        actionIntent = callIntent;
    } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE)
            || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) {
        RCConnection pendingConnection = getPendingConnection();
        if (pendingConnection != null) {
            pendingConnection.reject();
        }

        release();

        // if the call has been requested to be declined, we shouldn't do any UI handling
        return;
    } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_MUTE_AUDIO)) {
        RCConnection liveConnection = getLiveConnection();
        if (liveConnection != null) {
            if (liveConnection.isAudioMuted()) {
                liveConnection.setAudioMuted(false);
            } else {
                liveConnection.setAudioMuted(true);
            }
        }

        // if the call has been requested to be muted, we shouldn't do any UI handling
        return;
    } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DISCONNECT)) {
        RCConnection liveConnection = getLiveConnection();
        if (liveConnection != null) {
            liveConnection.disconnect();

            if (!isAttached()) {
                // if the call has been requested to be disconnected, we shouldn't do any UI handling
                callIntent.setAction(ACTION_CALL_DISCONNECT);
                //callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                actionIntent = callIntent;
                startActivity(actionIntent);
            }

            /*
            // Important if we just trigger the call intent, then after the call is disconnected we will land to the previous screen in
            // that Task Stack, which is not what we want. Instead, we want the call activity to be finished and to just remain where
            // we were. To do that we need to create a new Task Stack were we only place the call activity
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            // Adds the target Intent to the top of the stack
            stackBuilder.addNextIntent(actionIntent);
            // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            try {
               resultPendingIntent.send();
            }
            catch (PendingIntent.CanceledException e) {
               throw new RuntimeException("Pending Intent cancelled", e);
            }
            */
        }

        return;
    } else if (intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) {
        if (messageIntent == null) {
            storageManagerPreferences = new StorageManagerPreferences(this);
            String messageIntentString = storageManagerPreferences
                    .getString(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, null);
            if (messageIntentString != null) {
                try {
                    messageIntent = Intent.parseUri(messageIntentString, Intent.URI_INTENT_SCHEME);

                    //service was stopped and user taps on Notification case
                    if (!isInitialized()) {
                        HashMap<String, Object> parameters = StorageUtils.getParams(storageManagerPreferences);
                        try {
                            initialize(null, parameters, null);
                        } catch (RCException e) {
                            RCLogger.e(TAG, e.toString());
                        }
                    }
                } catch (URISyntaxException e) {
                    throw new RuntimeException("Failed to handle Notification");
                }
            }
        }
        messageIntent.setAction(ACTION_INCOMING_MESSAGE);

        // don't forget to copy the extras
        messageIntent.putExtras(intent);
        actionIntent = messageIntent;
        //we want to stop foreground (notification is tapped)
        stopForeground(true);
        stopRepeatingTask();
    } else {
        throw new RuntimeException("Failed to handle Notification");
    }

    // We need to create a Task Stack to make sure we maintain proper flow at all times
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds either call or message intent's Component in the stack together with all its parent activities (remember that for this to work the App Manifest needs to describe their relationship)
    stackBuilder.addParentStack(actionIntent.getComponent());
    // Adds the target Intent to the top of the stack
    stackBuilder.addNextIntent(actionIntent);
    // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    try {
        resultPendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        throw new RuntimeException("Pending Intent cancelled", e);
    }
}