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:net.olejon.mdapp.ManufacturerActivity.java

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

    // Intent/*w  w  w  .  jav a2 s . co  m*/
    final Intent intent = getIntent();

    final long manufacturerId = intent.getLongExtra("id", 0);

    // Layout
    setContentView(R.layout.activity_manufacturer);

    // Get manufacturer
    mSqLiteDatabase = new SlDataSQLiteHelper(mContext).getReadableDatabase();

    String[] manufacturersQueryColumns = { SlDataSQLiteHelper.MANUFACTURERS_COLUMN_NAME };
    mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MANUFACTURERS, manufacturersQueryColumns,
            SlDataSQLiteHelper.MANUFACTURERS_COLUMN_ID + " = " + manufacturerId, null, null, null, null);

    if (mCursor.moveToFirst()) {
        manufacturerName = mCursor
                .getString(mCursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MANUFACTURERS_COLUMN_NAME));

        String[] medicationsQueryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME, SlDataSQLiteHelper.MEDICATIONS_COLUMN_SUBSTANCE };
        mCursor = mSqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MEDICATIONS, medicationsQueryColumns,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_MANUFACTURER + " = " + mTools.sqe(manufacturerName), null,
                null, null, SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " COLLATE NOCASE");

        String[] fromColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME,
                SlDataSQLiteHelper.MEDICATIONS_COLUMN_SUBSTANCE };
        int[] toViews = { R.id.manufacturer_list_item_name, R.id.manufacturer_list_item_substance };

        SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(mContext,
                R.layout.activity_manufacturer_list_item, mCursor, fromColumns, toViews, 0);

        // Toolbar
        final Toolbar toolbar = (Toolbar) findViewById(R.id.manufacturer_toolbar);
        toolbar.setTitle(manufacturerName);

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Medications count
        int medicationsCount = mCursor.getCount();

        String medications = (medicationsCount == 1) ? getString(R.string.manufacturer_medication)
                : getString(R.string.manufacturer_medications);

        TextView medicationsCountTextView = (TextView) findViewById(R.id.manufacturer_medications_count);
        medicationsCountTextView.setText(medicationsCount + " " + medications);

        // List
        ListView listView = (ListView) findViewById(R.id.manufacturer_list);
        listView.setAdapter(simpleCursorAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (mCursor.moveToPosition(i)) {
                    long id = mCursor
                            .getLong(mCursor.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);
                }
            }
        });
    }
}

From source file:com.upenn.chriswang1990.sunshine.DetailFragment.java

private Intent createShareForecastIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    } else {/*from www.jav  a  2s. c  o  m*/
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    }
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, forecastStr + FORECAST_SHARE_HASHTAG);
    return shareIntent;
}

From source file:com.example.xyzreader.ui.articledetail.ArticleDetailFragment.java

private void sendArticle() {
    if (mCursor != null) {
        String title = mCursor.getString(ArticleLoader.Query.TITLE);
        String byline = ((TextView) mRootView.findViewById(R.id.article_detail_byline)).getText().toString();
        Spanned textBody = Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY));
        String photoUrl = mCursor.getString(ArticleLoader.Query.PHOTO_URL);

        Intent intent = new Intent();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        }//from  w ww . ja  v a 2 s  .c  om
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/*");
        intent.putExtra(Intent.EXTRA_SUBJECT, title);
        intent.putExtra(Intent.EXTRA_TEXT, title + "\n" + byline + "\n\n" + photoUrl + "\n\n" + textBody
                + "\n\n#" + mContext.getString(R.string.app_name));
        ShareActionProvider shareActionProvider = new ShareActionProvider(mContext);
        shareActionProvider.setShareIntent(intent);
        startActivity(intent);
    }
}

From source file:com.ruesga.rview.misc.ActivityHelper.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings("deprecation")
public static void share(Context ctx, String action, String title, String text) {
    try {/*  ww  w .j a v a2s .c  o m*/
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, title);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        } else {
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        }
        ctx.startActivity(Intent.createChooser(intent, action));

    } catch (ActivityNotFoundException ex) {
        // Fallback to default browser
        String msg = ctx.getString(R.string.exception_cannot_share_link);
        Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.heske.alexandria.activities.BookDetailFragment.java

public Intent getShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mActivity.getString(R.string.share_subject));
    shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text) + mBook.getTitle());
    return shareIntent;
}

From source file:net.gsantner.opoc.util.ActivityUtils.java

public void showGooglePlayEntryForThisApp() {
    String pkgId = "details?id=" + _activity.getPackageName();
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + pkgId));
    goToMarket/*from  ww  w  . ja v  a  2s . c om*/
            .addFlags(
                    Intent.FLAG_ACTIVITY_NO_HISTORY
                            | (Build.VERSION.SDK_INT >= 21 ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT
                                    : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
                            | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {
        _activity.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        _activity.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/" + pkgId)));
    }
}

From source file:saschpe.birthdays.fragment.SocialFragment.java

/**
 * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
 * has returned, but before any saved state has been restored in to the view.
 * This gives subclasses a chance to initialize themselves once
 * they know their view hierarchy has been completely created.  The fragment's
 * view hierarchy is not however attached to its parent at this point.
 *
 * @param view               The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
 * @param savedInstanceState If non-null, this fragment is being re-constructed
 *//*from ww w  .j a v  a2  s  .c  o  m*/
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    provideFeedback.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String subject = getString(R.string.feedback_mail_subject_template, getString(R.string.app_name));

            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", SUPPORT_EMAIL_ADDRESS[0], null))
                            .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, "")
                            .putExtra(Intent.EXTRA_EMAIL, SUPPORT_EMAIL_ADDRESS);
            startActivity(Intent.createChooser(emailIntent, view.getContext().getString(R.string.send_email)));
        }
    });
    followTwitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("twitter://user?screen_name=" + TWITTER_NAME)));
            } catch (ActivityNotFoundException e) {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + TWITTER_NAME)));
            }
        }
    });
    rateOnPlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // 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 >= 21) {
                flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
            } else {
                //noinspection deprecation
                flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
            }
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName))
                    .addFlags(flags);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)));
            }
        }
    });
    recommendToFriend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String subject = getString(R.string.get_app_template, getString(R.string.app_name));
            String body = Uri.parse("http://play.google.com/store/apps/details?id=" + packageName).toString();

            Intent sharingIntent = new Intent(Intent.ACTION_SEND).setType("text/plain")
                    .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, body);
            startActivity(Intent.createChooser(sharingIntent, view.getContext().getString(R.string.share_via)));
        }
    });
    forkOnGithub.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/saschpe/BirthdayCalendar")));
        }
    });
}

From source file:nextinnnovationsoft.com.weightlossrecepies.activity.MainActivity.java

private void openRate() {
    Uri uri = Uri.parse("market://details?id=" + context.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 {//  ww  w  . ja v 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=" + context.getPackageName())));
    }
}

From source file:net.kourlas.voipms_sms.Notifications.java

public void showNotifications(List<String> contacts) {
    if (!(ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationsActivity)) {
        Conversation[] conversations = Database.getInstance(applicationContext)
                .getConversations(preferences.getDid());
        for (Conversation conversation : conversations) {
            if (!conversation.isUnread() || !contacts.contains(conversation.getContact())
                    || (ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationActivity
                            && ((ConversationActivity) ActivityMonitor.getInstance().getCurrentActivity())
                                    .getContact().equals(conversation.getContact()))) {
                continue;
            }/*from   w w  w  .  ja  v  a 2  s. c  o  m*/

            String smsContact = Utils.getContactName(applicationContext, conversation.getContact());
            if (smsContact == null) {
                smsContact = Utils.getFormattedPhoneNumber(conversation.getContact());
            }

            String allSmses = "";
            String mostRecentSms = "";
            boolean initial = true;
            for (Message message : conversation.getMessages()) {
                if (message.getType() == Message.Type.INCOMING && message.isUnread()) {
                    if (initial) {
                        allSmses = message.getText();
                        mostRecentSms = message.getText();
                        initial = false;
                    } else {
                        allSmses = message.getText() + "\n" + allSmses;
                    }
                } else {
                    break;
                }
            }

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext);

            notificationBuilder.setContentTitle(smsContact);
            notificationBuilder.setContentText(mostRecentSms);
            notificationBuilder.setSmallIcon(R.drawable.ic_chat_white_24dp);
            notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
            notificationBuilder
                    .setSound(Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound()));
            notificationBuilder.setLights(0xFFAA0000, 1000, 5000);
            if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) {
                notificationBuilder.setVibrate(new long[] { 0, 250, 250, 250 });
            } else {
                notificationBuilder.setVibrate(new long[] { 0 });
            }
            notificationBuilder.setColor(0xFFAA0000);
            notificationBuilder.setAutoCancel(true);
            notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(allSmses));

            Bitmap largeIconBitmap;
            try {
                largeIconBitmap = MediaStore.Images.Media.getBitmap(applicationContext.getContentResolver(),
                        Uri.parse(Utils.getContactPhotoUri(applicationContext, conversation.getContact())));
                largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false);
                largeIconBitmap = Utils.applyCircularMask(largeIconBitmap);
                notificationBuilder.setLargeIcon(largeIconBitmap);
            } catch (Exception ignored) {

            }

            Intent intent = new Intent(applicationContext, ConversationActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(applicationContext.getString(R.string.conversation_extra_contact),
                    conversation.getContact());
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext);
            stackBuilder.addParentStack(ConversationActivity.class);
            stackBuilder.addNextIntent(intent);
            notificationBuilder
                    .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT));

            Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
            } else {
                //noinspection deprecation
                replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            }
            replyIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact),
                    conversation.getContact());
            PendingIntent replyPendingIntent = PendingIntent.getActivity(applicationContext, 0, replyIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            NotificationCompat.Action.Builder replyAction = new NotificationCompat.Action.Builder(
                    R.drawable.ic_reply_white_24dp,
                    applicationContext.getString(R.string.notifications_button_reply), replyPendingIntent);
            notificationBuilder.addAction(replyAction.build());

            Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class);
            markAsReadIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact),
                    conversation.getContact());
            PendingIntent markAsReadPendingIntent = PendingIntent.getBroadcast(applicationContext, 0,
                    markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            NotificationCompat.Action.Builder markAsReadAction = new NotificationCompat.Action.Builder(
                    R.drawable.ic_drafts_white_24dp,
                    applicationContext.getString(R.string.notifications_button_mark_read),
                    markAsReadPendingIntent);
            notificationBuilder.addAction(markAsReadAction.build());

            int id;
            if (notificationIds.get(conversation.getContact()) != null) {
                id = notificationIds.get(conversation.getContact());
            } else {
                id = notificationIdCount++;
                notificationIds.put(conversation.getContact(), id);
            }
            NotificationManager notificationManager = (NotificationManager) applicationContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(id, notificationBuilder.build());
        }
    }
}

From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_notification_settings:
        NotificationSettingsDialogFragment.showSettings(this);
        return true;
    case R.id.action_get_more_sources:
        FirebaseAnalytics.getInstance(getContext()).logEvent("more_sources_open", null);
        try {//  w ww. j a v  a2  s .co  m
            Intent playStoreIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/search?q=Muzei&c=apps"))
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
            preferPackageForIntent(playStoreIntent, PLAY_STORE_PACKAGE_NAME);
            startActivity(playStoreIntent);
        } catch (ActivityNotFoundException | SecurityException e) {
            Toast.makeText(getContext(), R.string.play_store_not_found, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}