Example usage for android.content Intent FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

List of usage examples for android.content Intent FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

Prototype

int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

To view the source code for android.content Intent FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

Click Source Link

Document

If set, the new activity is not kept in the list of recently launched activities.

Usage

From source file:com.digitalarx.android.files.services.FileDownloader.java

/**
 * Updates the status notification with the result of a download operation.
 * /*  w  ww .  ja  v  a  2s  .  c o m*/
 * @param downloadResult    Result of the download operation.
 * @param download          Finished download operation
 */
private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) {
    mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
    if (!downloadResult.isCancelled()) {
        int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker
                : R.string.downloader_download_failed_ticker;

        boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED
                || downloadResult.isIdPRedirection());
        tickerId = (needsToUpdateCredentials) ? R.string.downloader_download_failed_credentials_error
                : tickerId;

        mNotificationBuilder.setTicker(getString(tickerId)).setContentTitle(getString(tickerId))
                .setAutoCancel(true).setOngoing(false).setProgress(0, 0, false);

        if (needsToUpdateCredentials) {

            // let the user update credentials with one click
            Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount());
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                    AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
            mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this,
                    (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));

            mDownloadClient = null; // grant that future retries on the same account will get the fresh credentials

        } else {
            // TODO put something smart in showDetailsIntent
            Intent showDetailsIntent = new Intent();
            mNotificationBuilder.setContentIntent(
                    PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showDetailsIntent, 0));
        }

        mNotificationBuilder.setContentText(
                ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources()));
        mNotificationManager.notify(tickerId, mNotificationBuilder.build());

        // Remove success notification
        if (downloadResult.isSuccess()) {
            // Sleep 2 seconds, so show the notification before remove it
            NotificationDelayer.cancelWithDelay(mNotificationManager,
                    R.string.downloader_download_succeeded_ticker, 2000);
        }

    }
}

From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java

private synchronized void createView() {
    mView = mInflater.inflate(R.layout.recents_list_horizontal, null, false);
    mRecentListHorizontal = (HorizontalListView) mView.findViewById(R.id.recent_list_horizontal);

    mNoRecentApps = (TextView) mView.findViewById(R.id.no_recent_apps);

    mRecentListHorizontal.setSelectionListener(mSelectionGlowListener);

    mRecentListHorizontal.setOnItemClickListener(new OnItemClickListener() {
        @Override// w  w  w .j a va  2s . co  m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (DEBUG) {
                Log.d(TAG, "onItemClick");
            }
            TaskDescription task = mLoadedTasks.get(position);
            mRecentsManager.switchTask(task);
        }
    });

    mRecentListHorizontal.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (DEBUG) {
                Log.d(TAG, "onItemLongClick");
            }
            TaskDescription task = mLoadedTasks.get(position);
            handleLongPress(task, view);
            return true;
        }
    });

    SwipeDismissHorizontalListViewTouchListener touchListener = new SwipeDismissHorizontalListViewTouchListener(
            mRecentListHorizontal, new SwipeDismissHorizontalListViewTouchListener.DismissCallbacks() {
                public void onDismiss(HorizontalListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        TaskDescription ad = mRecentListAdapter.getItem(position);
                        mRecentsManager.killTask(ad);
                        break;
                    }
                }

                @Override
                public boolean canDismiss(int position) {
                    return true;
                }
            });

    mRecentListHorizontal.setSwipeListener(touchListener);
    mRecentListHorizontal.setAdapter(mRecentListAdapter);

    mOpenFavorite = (ImageButton) mView.findViewById(R.id.openFavorites);

    mOpenFavorite.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setButtonGlow(mOpenFavorite, mShowFavorites ? "arrow_up" : "arrow_down",
                    mShowFavorites ? R.drawable.arrow_up : R.drawable.arrow_down, true);

            mShowFavorites = !mShowFavorites;

            if (mConfiguration.mAnimate) {
                mFavoriteListHorizontal.startAnimation(
                        mShowFavorites ? getShowFavoriteAnimation() : getHideFavoriteAnimation());
            } else {
                mFavoriteListHorizontal.setVisibility(mShowFavorites ? View.VISIBLE : View.GONE);
                setButtonGlow(mOpenFavorite, mShowFavorites ? "arrow_up" : "arrow_down",
                        mShowFavorites ? R.drawable.arrow_up : R.drawable.arrow_down, false);
            }
        }
    });

    mFavoriteListHorizontal = (HorizontalListView) mView.findViewById(R.id.favorite_list_horizontal);

    mFavoriteListHorizontal.setSelectionListener(mSelectionGlowListener);

    mFavoriteListHorizontal.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (DEBUG) {
                Log.d(TAG, "onItemClick");
            }
            String intent = mFavoriteList.get(position);
            mRecentsManager.startIntentFromtString(intent);
        }
    });
    mFavoriteListHorizontal.setAdapter(mFavoriteListAdapter);

    mHomeButton = (GlowImageButton) mView.findViewById(R.id.home);
    mHomeButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.home));
    mHomeButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "home", mConfiguration.mGlowColor,
            mContext.getResources().getDrawable(R.drawable.home)));
    mHomeButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mHomeButton.setImageDrawable(mHomeButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });
    mHomeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.dismissAndGoHome();
            mHomeButton.setImageDrawable(mHomeButton.getOriginalImage());
        }
    });
    mHomeButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.home_help), Toast.LENGTH_SHORT)
                    .show();
            mHomeButton.setImageDrawable(mHomeButton.getOriginalImage());
            return true;
        }
    });

    mLastAppButton = (GlowImageButton) mView.findViewById(R.id.lastApp);
    mLastAppButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.lastapp));
    mLastAppButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "lastapp",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.lastapp)));
    mLastAppButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mLastAppButton.setImageDrawable(mLastAppButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });

    mLastAppButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.toggleLastApp();
            mLastAppButton.setImageDrawable(mLastAppButton.getOriginalImage());
        }
    });
    mLastAppButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.toogle_last_app_help),
                    Toast.LENGTH_SHORT).show();
            mLastAppButton.setImageDrawable(mLastAppButton.getOriginalImage());
            return true;
        }
    });
    mKillAllButton = (GlowImageButton) mView.findViewById(R.id.killAll);
    mKillAllButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.kill_all));
    mKillAllButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "kill_other",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.kill_all)));
    mKillAllButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mKillAllButton.setImageDrawable(mKillAllButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });
    mKillAllButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.killAll();
            mKillAllButton.setImageDrawable(mKillAllButton.getOriginalImage());
        }
    });

    mKillAllButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.kill_all_apps_help),
                    Toast.LENGTH_SHORT).show();
            mKillAllButton.setImageDrawable(mKillAllButton.getOriginalImage());
            return true;
        }
    });

    mKillOtherButton = (GlowImageButton) mView.findViewById(R.id.killOther);
    mKillOtherButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.kill_other));
    mKillOtherButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "kill_other",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.kill_other)));
    mKillOtherButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mKillOtherButton.setImageDrawable(mKillOtherButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });

    mKillOtherButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.killOther();
            mKillOtherButton.setImageDrawable(mKillOtherButton.getOriginalImage());
            mKillOtherButton.setImageDrawable(mKillOtherButton.getOriginalImage());
        }
    });
    mKillOtherButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.kill_other_apps_help),
                    Toast.LENGTH_SHORT).show();
            mKillOtherButton.setImageDrawable(mKillOtherButton.getOriginalImage());
            return true;
        }
    });

    mSettingsButton = (GlowImageButton) mView.findViewById(R.id.settings);
    mSettingsButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.settings));
    mSettingsButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "settings",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.settings)));

    mSettingsButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mSettingsButton.setImageDrawable(mSettingsButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });

    mSettingsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent hideRecent = new Intent(SwitchService.RecentsReceiver.ACTION_HIDE_OVERLAY);
            mContext.sendBroadcast(hideRecent);

            Intent mainActivity = new Intent(mContext, SettingsActivity.class);
            mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            mContext.startActivity(mainActivity);
            mSettingsButton.setImageDrawable(mSettingsButton.getOriginalImage());
        }
    });
    //mSettingsButton.setImageDrawable(Utils.getGlow(mContext.getResources(), "settings", mContext.getResources().getDrawable(R.drawable.settings)));
    mSettingsButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.settings_help),
                    Toast.LENGTH_SHORT).show();
            mSettingsButton.setImageDrawable(mSettingsButton.getOriginalImage());
            return true;
        }
    });

    // touches inside the overlay should not hide it
    mView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (DEBUG) {
                Log.d(TAG, "mView:onTouch");
            }
            return true;
        }
    });

    mRamUsageBar = (LinearColorBar) mView.findViewById(R.id.ram_usage_bar);
    mForegroundProcessText = (TextView) mView.findViewById(R.id.foregroundText);
    mBackgroundProcessText = (TextView) mView.findViewById(R.id.backgroundText);

    mPopupView = new FrameLayout(mContext);
    try {
        mPopupView.setBackground(mContext.getResources().getDrawable(R.drawable.overlay_bg));
    } catch (NoSuchMethodError x) {
        mPopupView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.overlay_bg));

    }
    mPopupView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (mShowing) {
                    if (DEBUG) {
                        Log.d(TAG, "mPopupView:onTouch");
                    }
                    Intent hideRecent = new Intent(SwitchService.RecentsReceiver.ACTION_HIDE_OVERLAY);
                    mContext.sendBroadcast(hideRecent);
                    return true;
                }
            }
            return false;
        }
    });
    mPopupView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (mShowing) {
                    if (DEBUG) {
                        Log.d(TAG, "onKey");
                    }
                    Intent hideRecent = new Intent(SwitchService.RecentsReceiver.ACTION_HIDE_OVERLAY);
                    mContext.sendBroadcast(hideRecent);
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.cerema.cloud2.files.services.FileDownloader.java

/**
 * Updates the status notification with the result of a download operation.
 *
 * @param downloadResult Result of the download operation.
 * @param download       Finished download operation
 *///w w  w  .j av  a  2  s.  c  o  m
private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) {
    mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
    if (!downloadResult.isCancelled()) {
        int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker
                : R.string.downloader_download_failed_ticker;

        boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED
                || downloadResult.isIdPRedirection());
        tickerId = (needsToUpdateCredentials) ? R.string.downloader_download_failed_credentials_error
                : tickerId;

        mNotificationBuilder.setTicker(getString(tickerId)).setContentTitle(getString(tickerId))
                .setAutoCancel(true).setOngoing(false).setProgress(0, 0, false);

        if (needsToUpdateCredentials) {

            // let the user update credentials with one click
            Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount());
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                    AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
            mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this,
                    (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));

        } else {
            // TODO put something smart in showDetailsIntent
            Intent showDetailsIntent = new Intent();
            mNotificationBuilder.setContentIntent(
                    PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showDetailsIntent, 0));
        }

        mNotificationBuilder.setContentText(
                ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources()));
        mNotificationManager.notify(tickerId, mNotificationBuilder.build());

        // Remove success notification
        if (downloadResult.isSuccess()) {
            // Sleep 2 seconds, so show the notification before remove it
            NotificationDelayer.cancelWithDelay(mNotificationManager,
                    R.string.downloader_download_succeeded_ticker, 2000);
        }

    }
}

From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java

public void showAppSettings() {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse("package:" + getContext().getPackageName()));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    getContext().startActivity(intent);/*from  w  ww.j  a  v  a  2 s  . c  om*/
}

From source file:org.durka.hallmonitor.CoreStateManager.java

public void requestAdmin() {
    if (!adminApp && preference_all.getBoolean("pref_lockmode", false) && configurationActivity != null) {
        ComponentName me = new ComponentName(mAppContext, AdminReceiver.class);
        Log.d(LOG_TAG, "launching dpm overlay");
        mAppContext.startActivity(new Intent(getContext(), Configuration.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
                        | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
        Log.d(LOG_TAG, "Started configuration activity.");
        Intent coup = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        coup.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, me);
        coup.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, mAppContext.getString(R.string.admin_excuse));
        getConfigurationActivity().startActivityForResult(coup, CoreApp.DEVICE_ADMIN_WAITING);
    }//from   w  ww  .ja va2 s.c o  m
}

From source file:com.irccloud.android.activity.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_RESOLVE_ERROR) {
        mResolvingError = false;/*w w w  .  j  av  a  2 s.c o m*/
        if (resultCode == RESULT_OK) {
            if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                mGoogleApiClient.connect();
            }
        }
    } else if (requestCode == REQUEST_RESOLVE_CREDENTIALS) {
        if (resultCode == RESULT_OK && data.hasExtra(Credential.EXTRA_KEY)) {
            Credential c = data.getParcelableExtra(Credential.EXTRA_KEY);
            name.setText(c.getName());
            email.setText(c.getId());
            password.setText(c.getPassword());
            loading.setVisibility(View.GONE);
            login.setVisibility(View.VISIBLE);
            loginHintClickListener.onClick(null);
            new LoginTask().execute((Void) null);
        } else {
            loading.setVisibility(View.GONE);
            login.setVisibility(View.VISIBLE);
        }
    } else if (requestCode == REQUEST_RESOLVE_SAVE_CREDENTIALS) {
        if (resultCode == RESULT_OK) {
            Log.e("IRCCloud", "Credentials result: OK");
        }
        Intent i = new Intent(LoginActivity.this, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        if (getIntent() != null) {
            if (getIntent().getData() != null)
                i.setData(getIntent().getData());
            if (getIntent().getExtras() != null)
                i.putExtras(getIntent().getExtras());
        }
        startActivity(i);
        finish();
    }
}

From source file:mgks.os.webview.MainActivity.java

public void show_notification(int type, int id) {
    long when = System.currentTimeMillis();
    asw_notification = (NotificationManager) MainActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent i = new Intent();
    if (type == 1) {
        i.setClass(MainActivity.this, MainActivity.class);
    } else if (type == 2) {
        i.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    } else {//  ww  w  .j  a  v  a2s  .  c  om
        i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.setData(Uri.parse("package:" + MainActivity.this.getPackageName()));
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    }
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, i,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this, "");
    switch (type) {
    case 1:
        builder.setTicker(getString(R.string.app_name));
        builder.setContentTitle(getString(R.string.loc_fail));
        builder.setContentText(getString(R.string.loc_fail_text));
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.loc_fail_more)));
        builder.setVibrate(new long[] { 350, 350, 350, 350, 350 });
        builder.setSmallIcon(R.mipmap.ic_launcher);
        break;

    case 2:
        builder.setTicker(getString(R.string.app_name));
        builder.setContentTitle(getString(R.string.loc_perm));
        builder.setContentText(getString(R.string.loc_perm_text));
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.loc_perm_more)));
        builder.setVibrate(new long[] { 350, 700, 350, 700, 350 });
        builder.setSound(alarmSound);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        break;
    }
    builder.setOngoing(false);
    builder.setAutoCancel(true);
    builder.setContentIntent(pendingIntent);
    builder.setWhen(when);
    builder.setContentIntent(pendingIntent);
    asw_notification_new = builder.build();
    asw_notification.notify(id, asw_notification_new);
}

From source file:com.cerema.cloud2.ui.activity.FileActivity.java

/**
 * Invalidates the credentials stored for the current OC account and requests new credentials to the user,
 * navigating to {@link AuthenticatorActivity}
 *
 * @param context   Android Context needed to access the {@link AccountManager}. Received as a parameter
 *                  to make the method accessible to {@link android.content.BroadcastReceiver}s.
 *//*from   w ww  . j a v  a2s .c om*/
protected void requestCredentialsUpdate(Context context) {

    try {
        /// step 1 - invalidate credentials of current account
        OwnCloudClient client;
        OwnCloudAccount ocAccount = new OwnCloudAccount(getAccount(), context);
        client = (OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(ocAccount));
        if (client != null) {
            OwnCloudCredentials cred = client.getCredentials();
            if (cred != null) {
                AccountManager am = AccountManager.get(context);
                if (cred.authTokenExpires()) {
                    am.invalidateAuthToken(getAccount().type, cred.getAuthToken());
                } else {
                    am.clearPassword(getAccount());
                }
            }
        }

        /// step 2 - request credentials to user
        Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
        updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivity(updateAccountCredentials);

    } catch (com.cerema.cloud2.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        Toast.makeText(context, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
    }

}

From source file:com.synox.android.ui.activity.FileActivity.java

/**
 * Invalidates the credentials stored for the current OC account and requests new credentials to the user,
 * navigating to {@link AuthenticatorActivity}
 *
 * @param context Android Context needed to access the {@link AccountManager}. Received as a parameter
 *                to make the method accessible to {@link android.content.BroadcastReceiver}s.
 *///from w w w  . j  av  a2  s  .  c  o m
protected void requestCredentialsUpdate(Context context) {

    try {
        /// step 1 - invalidate credentials of current account
        OwnCloudClient client;
        OwnCloudAccount ocAccount = new OwnCloudAccount(getAccount(), context);
        client = (OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(ocAccount));
        if (client != null) {
            OwnCloudCredentials cred = client.getCredentials();
            if (cred != null) {
                AccountManager am = AccountManager.get(context);
                if (cred.authTokenExpires()) {
                    am.invalidateAuthToken(getAccount().type, cred.getAuthToken());
                } else {
                    am.clearPassword(getAccount());
                }
            }
        }

        /// step 2 - request credentials to user
        Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
        updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
        updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivity(updateAccountCredentials);

    } catch (com.synox.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
        Toast.makeText(context, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
    }

}

From source file:com.digitalarx.android.files.services.FileUploader.java

/**
 * Updates the status notification with the result of an upload operation.
 * //from w ww . ja  v a  2 s  .com
 * @param uploadResult Result of the upload operation.
 * @param upload Finished upload operation
 */
private void notifyUploadResult(RemoteOperationResult uploadResult, UploadFileOperation upload) {
    Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode());
    // / cancelled operation or success -> silent removal of progress notification
    mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);

    // Show the result: success or fail notification
    if (!uploadResult.isCancelled()) {
        int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker
                : R.string.uploader_upload_failed_ticker;

        NotificationCompat.Builder resultBuilder = new NotificationCompat.Builder(this);

        String content = null;

        // check credentials error
        boolean needsToUpdateCredentials = (uploadResult.getCode() == ResultCode.UNAUTHORIZED
                || uploadResult.isIdPRedirection());
        tickerId = (needsToUpdateCredentials) ? R.string.uploader_upload_failed_credentials_error : tickerId;

        resultBuilder.setSmallIcon(R.drawable.notification_icon).setTicker(getString(tickerId))
                .setContentTitle(getString(tickerId)).setAutoCancel(true);

        content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources());

        if (needsToUpdateCredentials) {
            // let the user update credentials with one click
            Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount());
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                    AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
            resultBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                    updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));

            mUploadClient = null; // grant that future retries on the same account will get the fresh credentials
        } else {
            // TODO put something smart in the contentIntent below

            // we add only for instant-uploads the InstantUploadActivity and the
            // db entry
            Intent detailUploadIntent = new Intent(this, InstantUploadActivity.class);
            detailUploadIntent.putExtra(FileUploader.KEY_ACCOUNT, upload.getAccount());
            resultBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                    detailUploadIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT))
                    .setContentText(content);

            if (upload.isInstant()) {
                DbHandler db = null;
                try {
                    db = new DbHandler(this.getBaseContext());
                    String message = uploadResult.getLogMessage() + " errorCode: " + uploadResult.getCode();
                    Log_OC.e(TAG, message + " Http-Code: " + uploadResult.getHttpCode());
                    if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) {
                        message = getString(R.string.failed_upload_quota_exceeded_text);
                        if (db.updateFileState(upload.getOriginalStoragePath(),
                                DbHandler.UPLOAD_STATUS_UPLOAD_FAILED, message) == 0) {
                            db.putFileForLater(upload.getOriginalStoragePath(), upload.getAccount().name,
                                    message);
                        }
                    }
                } finally {
                    if (db != null) {
                        db.close();
                    }
                }
            }
        }

        resultBuilder.setContentText(content);
        mNotificationManager.notify(tickerId, resultBuilder.build());

        if (uploadResult.isSuccess()) {

            DbHandler db = new DbHandler(this.getBaseContext());
            db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
            db.close();

            // remove success notification, with a delay of 2 seconds
            NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.uploader_upload_succeeded_ticker,
                    2000);

        }
    }
}