Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

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

Click Source Link

Usage

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private void handleDecodeExternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    if (barcode != null) {
        viewfinderView.drawResultBitmap(barcode);
    }//from   w  ww.ja  v a  2s. c  om

    long resultDurationMS;
    if (getIntent() == null) {
        resultDurationMS = DEFAULT_INTENT_RESULT_DURATION_MS;
    } else {
        resultDurationMS = getIntent().getLongExtra(Intents.Scan.RESULT_DISPLAY_DURATION_MS,
                DEFAULT_INTENT_RESULT_DURATION_MS);
    }

    if (resultDurationMS > 0) {
        String rawResultString = String.valueOf(rawResult);
        if (rawResultString.length() > 32) {
            rawResultString = rawResultString.substring(0, 32) + " ...";
        }
        statusView.setText(getString(resultHandler.getDisplayTitle()) + " : " + rawResultString);
    }

    //        if (copyToClipboard && !resultHandler.areContentsSecure()) {
    //            CharSequence text = resultHandler.getDisplayContents();
    //            ClipboardInterface.setText(text, this);
    //        }

    if (source == IntentSource.NATIVE_APP_INTENT) {

        // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
        // the deprecated intent is retired.
        Intent intent = new Intent(getIntent().getAction());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
        intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
        byte[] rawBytes = rawResult.getRawBytes();
        if (rawBytes != null && rawBytes.length > 0) {
            intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
        }
        Map<ResultMetadataType, ?> metadata = rawResult.getResultMetadata();
        if (metadata != null) {
            if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
                intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION,
                        metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
            }
            Number orientation = (Number) metadata.get(ResultMetadataType.ORIENTATION);
            if (orientation != null) {
                intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
            }
            String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
            if (ecLevel != null) {
                intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
            }
            @SuppressWarnings("unchecked")
            Iterable<byte[]> byteSegments = (Iterable<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
            if (byteSegments != null) {
                int i = 0;
                for (byte[] byteSegment : byteSegments) {
                    intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
                    i++;
                }
            }
        }
        sendReplyMessage(R.id.return_scan_result, intent, resultDurationMS);

    } else if (source == IntentSource.PRODUCT_SEARCH_LINK) {

        // Reformulate the URL which triggered us into a query, so that the request goes to the same
        // TLD as the scan URL.
        int end = sourceUrl.lastIndexOf("/scan");
        String replyURL = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents()
                + "&source=zxing";
        sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);

    } else if (source == IntentSource.ZXING_LINK) {

        //            if (scanFromWebPageManager != null && scanFromWebPageManager.isScanFromWebPage()) {
        //                String replyURL = scanFromWebPageManager.buildReplyURL(rawResult, resultHandler);
        //                scanFromWebPageManager = null;
        //                sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);
        //            }

    }
}

From source file:com.jimandreas.popularmovies.MovieDetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (mShareDetails == null) {
        return super.onOptionsItemSelected(item);
    }//  ww w  .j  a va 2 s. co m
    //        if (getActivity() instanceof MovieDetailActivity) {
    //            return super.onOptionsItemSelected(item);
    //        }
    if (id == R.id.action_share) {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, mShareDetails);
        this.startActivity(shareIntent);
    }

    //        if (id == R.id.action_refresh) {
    //
    //            // TODO : get status of popular or top_rated...
    //            FetchMovieListTask mFetchMovieListTask = new FetchMovieListTask(this);
    //            mFetchMovieListTask.execute(
    //                    mFetchMovieListTask.FETCH_POPULAR, "1");
    //            return true;
    //        }
    //
    //        //noinspection SimplifiableIfStatement
    //        if (id == R.id.action_settings) {
    //            return true;
    //        }

    return super.onOptionsItemSelected(item);
}

From source file:com.bookkos.bircle.CaptureActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    switch (item.getItemId()) {
    case R.id.menu_group_select:
        intent.setClassName(this, GroupSelectActivity.class.getName());
        startActivity(intent);//from w  ww .j  a v a  2  s .c  om
        break;
    case R.id.menu_web_view:
        intent.setClassName(this, WebViewActivity.class.getName());
        startActivity(intent);
        break;
    case R.id.menu_logout:
        logout();
        break;
    case R.id.menu_open_source_license:
        openSourceLicenseDialog();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.tct.mail.browse.MessageAttachmentBar.java

private void importXvcard(Attachment attachment, final String type) {
    new AsyncTask<Attachment, Void, Uri>() {

        @Override/*from  w  w w .  j a va2  s. co m*/
        protected Uri doInBackground(Attachment... params) {
            final Attachment attach = params[0];
            final String[] filenames = mContext.fileList();
            for (String file : filenames) {
                if (file.endsWith(".vcf")) {
                    mContext.deleteFile(file);
                }
            }
            try {
                InputStream in = null;
                OutputStream out = null;
                try {
                    in = mContext.getContentResolver().openInputStream(attach.contentUri);
                    out = mContext.openFileOutput(attach.getName(), Context.MODE_WORLD_READABLE);
                    byte[] buf = new byte[8096];
                    int seg = 0;
                    while ((seg = in.read(buf)) != -1) {
                        out.write(buf, 0, seg);
                    }
                } finally {
                    if (in != null) {
                        in.close();
                    }
                    if (out != null) {
                        out.close();
                    }
                }
            } catch (FileNotFoundException e) {
                LogUtils.e(LOG_TAG, "importVCard, file not found " + attach + ", exception ", e);
            } catch (IOException e) {
                LogUtils.e(LOG_TAG, "importVCard, ioexception " + attach + ", exception ", e);
            } catch (Exception e) {
                LogUtils.e(LOG_TAG, "importVCard, unknown errror ", e);
            }
            final File tempVCard = mContext.getFileStreamPath(attach.getName());
            if (!tempVCard.exists() || tempVCard.length() <= 0) {
                LogUtils.e(LOG_TAG, "importVCard, file is not exists or empty " + tempVCard);
                return null;
            }
            return Uri.fromFile(tempVCard);
        }

        @Override
        protected void onPostExecute(Uri uri) {
            super.onPostExecute(uri);
            if (uri == null)
                return;
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            Utils.setIntentDataAndTypeAndNormalize(intent, uri, type);
            try {
                getContext().startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // couldn't find activity for View intent
                LogUtils.e(LOG_TAG, e, "Couldn't find Activity for intent");
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                int dialogMessage = R.string.no_application_found;
                builder.setTitle(R.string.more_info_attachment).setMessage(dialogMessage).show();
            }
        }
    }.execute(attachment);
}

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

/**
 * To share a document by its path.<br/>
 * This will send a share intent./*from  w w w .  j  av a  2 s .  c  o  m*/
 *
 * @param path the file path to share
 */
private void shareDocument(String path) {
    // create an intent, so the user can choose which application he/she wants to use to share this file
    final Intent intent = ShareCompat.IntentBuilder.from(this)
            .setType(MimeTypeMap.getSingleton()
                    .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path)))
            .setStream(FileProvider.getUriForFile(this, "com.orange.ocara", exportFile))
            .setChooserTitle("How do you want to share?").createChooserIntent()
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    startActivityForResult(intent, ACTION_SHARE_DOCUMENT);
}

From source file:com.gmail.charleszq.picorner.ui.ImageDetailFragment.java

private Intent createShareIntent(String filename) {
    File shareFile = getShareImageFile(filename);
    Uri uri = Uri.fromFile(shareFile);/*from   ww  w.  jav a2  s. co  m*/

    StringBuilder sb = new StringBuilder();
    sb.append(ImageUtils.getPhotoShareLink(mPhoto));
    sb.append(" ").append(getString(R.string.share_via)).append(" "); //$NON-NLS-1$//$NON-NLS-2$
    sb.append(getString(R.string.app_name));
    sb.append(" ").append(IConstants.APP_GL_STORE_URL); //$NON-NLS-1$
    saveToClipboard(sb.toString());

    Intent shareIntent = ShareCompat.IntentBuilder.from(getActivity()).setText(sb.toString()).setType("image/*") //$NON-NLS-1$
            .setStream(uri).createChooserIntent();
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    return shareIntent;
}

From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java

private void handleDecodeExternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    if (barcode != null) {
        viewfinderView.drawResultBitmap(barcode);
    }//w w  w .ja va 2s . com

    long resultDurationMS;
    if (getIntent() == null) {
        resultDurationMS = DEFAULT_INTENT_RESULT_DURATION_MS;
    } else {
        resultDurationMS = getIntent().getLongExtra(Intents.Scan.RESULT_DISPLAY_DURATION_MS,
                DEFAULT_INTENT_RESULT_DURATION_MS);
    }

    // Since this message will only be shown for a second, just tell the
    // user what kind of
    // barcode was found (e.g. contact info) rather than the full contents,
    // which they won't
    // have time to read.
    if (resultDurationMS > 0) {
        statusView.setText(getString(resultHandler.getDisplayTitle()));
    }

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        CharSequence text = resultHandler.getDisplayContents();
        if (text != null) {
            clipboard.setText(text);
        }
    }

    if (source == IntentSource.NATIVE_APP_INTENT) {

        // Hand back whatever action they requested - this can be changed to
        // Intents.Scan.ACTION when
        // the deprecated intent is retired.
        Intent intent = new Intent(getIntent().getAction());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
        intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
        byte[] rawBytes = rawResult.getRawBytes();
        if (rawBytes != null && rawBytes.length > 0) {
            intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
        }
        Map<ResultMetadataType, ?> metadata = rawResult.getResultMetadata();
        if (metadata != null) {
            if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
                intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION,
                        metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
            }
            Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);
            if (orientation != null) {
                intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
            }
            String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
            if (ecLevel != null) {
                intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
            }
            Iterable<byte[]> byteSegments = (Iterable<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
            if (byteSegments != null) {
                int i = 0;
                for (byte[] byteSegment : byteSegments) {
                    intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
                    i++;
                }
            }
        }
        sendReplyMessage(R.id.return_scan_result, intent, resultDurationMS);

    } else if (source == IntentSource.PRODUCT_SEARCH_LINK) {

        // Reformulate the URL which triggered us into a query, so that the
        // request goes to the same
        // TLD as the scan URL.
        int end = sourceUrl.lastIndexOf("/scan");
        String replyURL = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents()
                + "&source=zxing";
        sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);

    } else if (source == IntentSource.ZXING_LINK) {

        // Replace each occurrence of RETURN_CODE_PLACEHOLDER in the
        // returnUrlTemplate
        // with the scanned code. This allows both queries and REST-style
        // URLs to work.
        if (returnUrlTemplate != null) {
            CharSequence codeReplacement = returnRaw ? rawResult.getText() : resultHandler.getDisplayContents();
            try {
                codeReplacement = URLEncoder.encode(codeReplacement.toString(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // can't happen; UTF-8 is always supported. Continue, I
                // guess, without encoding
            }
            String replyURL = returnUrlTemplate.replace(RETURN_CODE_PLACEHOLDER, codeReplacement);
            sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);
        }

    }
}

From source file:com.onesignal.OneSignal.java

private static boolean openURLFromNotification(Context context, JSONArray dataArray) {
    int jsonArraySize = dataArray.length();

    boolean urlOpened = false;

    for (int i = 0; i < jsonArraySize; i++) {
        try {/*  www  . j ava 2s .  co  m*/
            JSONObject data = dataArray.getJSONObject(i);
            if (!data.has("custom"))
                continue;

            JSONObject customJSON = new JSONObject(data.getString("custom"));

            if (customJSON.has("u")) {
                String url = customJSON.getString("u");
                if (!url.contains("://"))
                    url = "http://" + url;

                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
                        | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                urlOpened = true;
            }
        } catch (Throwable t) {
            Log(LOG_LEVEL.ERROR,
                    "Error parsing JSON item " + i + "/" + jsonArraySize + " for launching a web URL.", t);
        }
    }

    return urlOpened;
}

From source file:com.android.email.activity.MessageView.java

public void onClick(View view) {
    switch (view.getId()) {
    case R.id.from:
    case R.id.presence:
        onClickSender();/*from   w  ww.  j av a2  s  .  c  o  m*/
        break;
    case R.id.favorite:
        onClickFavorite();
        break;
    case R.id.reply:
        onReply();
        break;
    case R.id.reply_all:
        onReplyAll();
        break;
    case R.id.delete:
        onDelete();
        break;
    case R.id.moveToOlder:
        moveToOlder();
        break;
    case R.id.moveToNewer:
        moveToNewer();
        break;
    case R.id.download:
        onDownloadAttachment((AttachmentInfo) view.getTag());
        break;
    case R.id.view:
        onViewAttachment((AttachmentInfo) view.getTag());
        break;
    case R.id.show_pictures:
        onShowPictures();
        break;
    case R.id.accept:
        onRespond(EmailServiceConstants.MEETING_REQUEST_ACCEPTED, R.string.message_view_invite_toast_yes);
        break;
    case R.id.maybe:
        onRespond(EmailServiceConstants.MEETING_REQUEST_TENTATIVE, R.string.message_view_invite_toast_maybe);
        break;
    case R.id.decline:
        onRespond(EmailServiceConstants.MEETING_REQUEST_DECLINED, R.string.message_view_invite_toast_no);
        break;
    case R.id.invite_link:
        String startTime = new PackedString(mMessage.mMeetingInfo).get(MeetingInfo.MEETING_DTSTART);
        if (startTime != null) {
            long epochTimeMillis = Utility.parseEmailDateTimeToMillis(startTime);
            Uri uri = Uri.parse("content://com.android.calendar/time/" + epochTimeMillis);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(uri);
            intent.putExtra("VIEW", "DAY");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            startActivity(intent);
        } else {
            Email.log("meetingInfo without DTSTART " + mMessage.mMeetingInfo);
        }
        break;
    }
}

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

private void buildLinksSection(Cursor cursor) {
    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) findViewById(com.saarang.samples.apps.iosched.R.id.links_container);
    linkContainer.removeAllViews();//from ww  w  .j a v a  2 s . co m

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(this);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(com.saarang.samples.apps.iosched.R.string.session_link_livestream,
                getWatchLiveIntent(this)));
    }

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(
                com.saarang.samples.apps.iosched.R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Object>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(this);
        int columns = getResources().getInteger(com.saarang.samples.apps.iosched.R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Object> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(
                    com.saarang.samples.apps.iosched.R.layout.list_item_session_link, linkContainer, false);
            if (link.first == com.saarang.samples.apps.iosched.R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(
                            com.saarang.samples.apps.iosched.R.layout.include_link_row, linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        findViewById(com.saarang.samples.apps.iosched.R.id.session_links_header).setVisibility(View.VISIBLE);
        findViewById(com.saarang.samples.apps.iosched.R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        findViewById(com.saarang.samples.apps.iosched.R.id.session_links_header).setVisibility(View.GONE);
        findViewById(com.saarang.samples.apps.iosched.R.id.links_container).setVisibility(View.GONE);
    }

}