Example usage for android.content Intent FLAG_ACTIVITY_NEW_DOCUMENT

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_DOCUMENT

Introduction

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

Prototype

int FLAG_ACTIVITY_NEW_DOCUMENT

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

Click Source Link

Document

This flag is used to open a document into a new task rooted at the activity launched by this Intent.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getActivityNewDocumentFlag() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
    } else {/*  w w w .ja  v a 2s  . c  o m*/
        return Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
    }
}

From source file:Main.java

public static void shareText(Context context, String title, String subject, String text, String mime) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType(mime);//  www.  j a v  a 2 s .  c om
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

    // Add data to the intent, the receiving app will decide
    // what to do with it.
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT, text);

    context.startActivity(Intent.createChooser(share, title));
}

From source file:Main.java

/**
 * @return {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} on API 21 and above and {@link Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET} on other versions
 *///w ww.j  ava 2  s  .  c  o m
@TargetApi(21)
public static int getNewDocumentIntentFlag() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
    } else {
        //noinspection deprecation
        return Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
    }
}

From source file:Main.java

@SuppressLint("InlinedApi")
public static void launchPlainText(Context context, String text, CharSequence chooserTitle) {
    // See http://android-developers.blogspot.com/2012/02/share-with-intents.html
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    // intent.putExtra( Intent.EXTRA_SUBJECT, subject );
    // intent.putExtra( Intent.EXTRA_EMAIL, new String[] { emailTo } );
    context.startActivity(Intent.createChooser(intent, chooserTitle));
}

From source file:com.kobi.metalsexchange.app.CalculateFragment.java

private Intent createShareExchangeRatesIntent(String calcResult) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, calcResult);
    return shareIntent;
}

From source file:com.creationgroundmedia.popularmovies.trailers.TrailerFragment.java

@Override
public void onLoadFinished(Loader<List<TrailerItem>> loader, final List<TrailerItem> data) {
    if (data != null) {
        FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override//www .  jav a2s. c  om
            public void onClick(View view) {
                if (data.size() > 0) {
                    TrailerItem trailer = data.get(0);
                    Intent intent = new Intent();
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                    intent.setAction(Intent.ACTION_SEND);
                    intent.setType("text/*");
                    intent.putExtra(Intent.EXTRA_SUBJECT, trailer.getName());
                    intent.putExtra(Intent.EXTRA_TEXT, "https://www.youtube.com/watch?v="
                            + trailer.getYoutubeKey() + "\n\n#PopularMoviesApp");
                    ShareActionProvider shareActionProvider = new ShareActionProvider(getContext());
                    shareActionProvider.setShareIntent(intent);
                    startActivity(intent);
                } else {
                    Snackbar.make(view, "No trailers to share for this movie", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            }
        });
        for (TrailerItem trailer : data) {
            View tv = LayoutInflater.from(getContext()).inflate(R.layout.fragment_trailer, null);
            ((LinearLayout) mView).addView(tv);
            TextView nameView = (TextView) tv.findViewById(R.id.content);
            nameView.setText(trailer.getName());
            /**
             * the YouTube key is tucked into a hidden (GONE) TextView so that it can be used
             * to build a URL if the user clicks the enrty
             * */
            TextView keyView = (TextView) tv.findViewById(R.id.youtube_key);
            keyView.setText(trailer.getYoutubeKey());
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    launchTrailerViewer(((TextView) v.findViewById(R.id.youtube_key)).getText());
                }
            });
        }
        getLoaderManager().destroyLoader(URL_TRAILERLOADER);
    }
}

From source file:com.vixir.finalproject.perfectday.fragment.MoreInfoFragment.java

@OnClick(R.id.rate_the_app)
public void onClickRateTheApp() {
    Uri uri = Uri.parse("market://details?id=" + getContext().getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT
            | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {//from   www .j  av  a  2s.  c o  m
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + getContext().getPackageName())));
    }
}

From source file:com.jpventura.alexandria.BookDetail.java

@Override
public void onLoadFinished(android.support.v4.content.Loader<Cursor> loader, Cursor data) {
    if (!data.moveToFirst()) {
        return;//from   w  w  w  .ja  v a2 s .  c  o  m
    }

    bookTitle = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.TITLE));
    ((TextView) rootView.findViewById(R.id.fullBookTitle)).setText(bookTitle);

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text) + bookTitle);
    shareActionProvider.setShareIntent(shareIntent);

    String bookSubTitle = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.SUBTITLE));
    ((TextView) rootView.findViewById(R.id.fullBookSubTitle)).setText(bookSubTitle);

    String desc = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.DESC));
    ((TextView) rootView.findViewById(R.id.fullBookDesc)).setText(desc);

    String authors = data.getString(data.getColumnIndex(AlexandriaContract.AuthorEntry.AUTHOR));
    String[] authorsArr = authors.split(",");
    ((TextView) rootView.findViewById(R.id.authors)).setLines(authorsArr.length);
    ((TextView) rootView.findViewById(R.id.authors)).setText(authors.replace(",", "\n"));
    String imgUrl = data.getString(data.getColumnIndex(AlexandriaContract.BookEntry.IMAGE_URL));
    if (Patterns.WEB_URL.matcher(imgUrl).matches()) {
        new DownloadImage((ImageView) rootView.findViewById(R.id.fullBookCover)).execute(imgUrl);
        rootView.findViewById(R.id.fullBookCover).setVisibility(View.VISIBLE);
    }

    String categories = data.getString(data.getColumnIndex(AlexandriaContract.CategoryEntry.CATEGORY));
    ((TextView) rootView.findViewById(R.id.categories)).setText(categories);

    if (rootView.findViewById(R.id.right_container) != null) {
        rootView.findViewById(R.id.backButton).setVisibility(View.INVISIBLE);
    }

}

From source file:com.owncloud.android.ui.dialog.RateMeDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Create a view by inflating desired layout
    View v = inflater.inflate(R.layout.rate_me_dialog, container, false);

    Button rateNowButton = v.findViewById(R.id.button_rate_now);
    Button laterButton = v.findViewById(R.id.button_later);
    Button noThanksButton = v.findViewById(R.id.button_no_thanks);
    TextView titleView = v.findViewById(R.id.rate_me_dialog_title_view);

    titleView.setText(String.format(getString(R.string.rate_dialog_title), getString(R.string.app_name)));

    rateNowButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w. j  a  v a2s  . c  o m*/
        public void onClick(View v) {
            String packageName = getArguments().getString(APP_PACKAGE_NAME);
            Uri uri = Uri.parse(MARKET_DETAILS_URI + packageName);
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

            /// To count with Play market back stack, After pressing back button,
            /// to taken back to our application, we need to add following flags to intent.
            int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
            } else {
                flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
            }
            goToMarket.addFlags(flags);

            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                getActivity()
                        .startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PLAY_STORE_URI + packageName)));
            }
            dialog.dismiss();
        }
    });

    laterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences preferences = getActivity().getSharedPreferences(AppRater.APP_RATER_PREF_TITLE,
                    0);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putLong(AppRater.APP_RATER_PREF_DATE_NEUTRAL, System.currentTimeMillis());
            editor.apply();
            dialog.dismiss();
        }
    });

    noThanksButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences preferences = getActivity().getSharedPreferences(AppRater.APP_RATER_PREF_TITLE,
                    0);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean(AppRater.APP_RATER_PREF_DONT_SHOW, true);
            editor.apply();
            dialog.dismiss();
        }
    });

    return v;
}

From source file:net.olejon.mdapp.BarcodeScannerActivity.java

@Override
public void handleResult(Result result) {
    mTools.showToast(getString(R.string.barcode_scanner_wait), 0);

    String barcode = result.getText();

    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website_uri) + "api/1/barcode/?search=" + barcode,
            new Response.Listener<JSONObject>() {
                @Override//from w w  w. ja  v  a  2s .c o  m
                public void onResponse(JSONObject response) {
                    try {
                        String medicationName = response.getString("name");

                        if (medicationName.equals("")) {
                            mTools.showToast(getString(R.string.barcode_scanner_no_results), 1);

                            finish();
                        } else {
                            SQLiteDatabase sqLiteDatabase = new SlDataSQLiteHelper(mContext)
                                    .getReadableDatabase();

                            String[] queryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID };
                            Cursor cursor = sqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MEDICATIONS,
                                    queryColumns,
                                    SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " LIKE "
                                            + mTools.sqe("%" + medicationName + "%") + " COLLATE NOCASE",
                                    null, null, null, null);

                            if (cursor.moveToFirst()) {
                                long id = cursor.getLong(
                                        cursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID));

                                Intent intent = new Intent(mContext, MedicationActivity.class);

                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    if (mTools.getDefaultSharedPreferencesBoolean(
                                            "MEDICATION_MULTIPLE_DOCUMENTS"))
                                        intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                                                | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                                }

                                intent.putExtra("id", id);
                                startActivity(intent);
                            }

                            cursor.close();
                            sqLiteDatabase.close();

                            finish();
                        }
                    } catch (Exception e) {
                        mTools.showToast(getString(R.string.barcode_scanner_no_results), 1);

                        Log.e("BarcodeScannerActivity", Log.getStackTraceString(e));

                        finish();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("FelleskatalogenService", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);
}