Example usage for android.content Intent EXTRA_STREAM

List of usage examples for android.content Intent EXTRA_STREAM

Introduction

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

Prototype

String EXTRA_STREAM

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

Click Source Link

Document

A content: URI holding a stream of data associated with the Intent, used with #ACTION_SEND to supply the data being sent.

Usage

From source file:com.android.gallery3d.app.PhotoPage.java

private static Intent createShareIntent(MediaObject mediaObject) {
    int type = mediaObject.getMediaType();
    return new Intent(Intent.ACTION_SEND).setType(MenuExecutor.getMimeType(type))
            .putExtra(Intent.EXTRA_STREAM, mediaObject.getContentUri())
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

From source file:com.android.gallery3d.app.PhotoPage.java

private static Intent createSharePanoramaIntent(Uri contentUri) {
    return new Intent(Intent.ACTION_SEND).setType(GalleryUtils.MIME_TYPE_PANORAMA360)
            .putExtra(Intent.EXTRA_STREAM, contentUri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

From source file:com.terraremote.terrafieldreport.OpenGroundReport.java

public void submitDailyGroundTailgate() {

    gatherValues();/*from  w ww.  ja  v  a 2  s  .  c om*/
    GroundJsonObjectBuilder();

    String dailyTailgateText = createDailyTailgate(name, userSelectedDateGround, submissionDate, reSubmit,
            transitDay, phoneNumber, mobNumber, workingAlone, colleagues, locationStart, gpsLatitude,
            gpsLongitude, hiVisApparel, clothingForSeason, safetyRatedFootwear, personalSurvivalKit,
            hearingProtection, hardHat, ppeComments, rentalVehicle, rentalAgency, vehicleMake, vehicleModel,
            vehicleColour, vehicleLicensePlate, vehicleOperatorName, cityOfDeparture, cityOfArrival,
            projectLocation, projectDescription, estimatedWorkDuration, checkInContactRole, checkInContactName,
            satellitePhone, satellitePhoneNumber, radio, firstAidKit, fireExtinguisher, transportingFuel,
            tdgPlacards, spillKit, workingInTraffic, pylons, trafficSigns, appropriateVehicle, remoteArea,
            workingInIsolation, extremeWeather, transmissionLines, activeMineSite, activeLoggingArea, wildlife,
            fatigue, politicalConflict, riskLevel, preventionMeasures, postRiskLevel, generalComments);

    writeJsonFileToExternalStorage();

    // New email method (attaching .json file instead of .csv)
    File Dir = new File(String.valueOf(getExternalFilesDir(null)) + "/GroundReports");
    String jsonReportTextFileName = "OpenGround_Report.json";
    File jsonReportFile = new File(Dir, jsonReportTextFileName);

    Uri uri = FileProvider.getUriForFile(OpenGroundReport.this, BuildConfig.APPLICATION_ID + ".provider",
            jsonReportFile);

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("plain/text");
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.email_address) });
    intent.putExtra(Intent.EXTRA_SUBJECT, "Open Ground Report" + "-" + "MOB(" + mobNumber + ")-" + name + "-"
            + userSelectedDateGround + "-" + "Field_Report");
    intent.putExtra(Intent.EXTRA_TEXT, dailyTailgateText);

    if (!jsonReportFile.exists() || !jsonReportFile.canRead()) {
        return;
    }

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(Intent.createChooser(intent, getString(R.string.pick_email_provider)));
    }
}

From source file:com.crearo.gpslogger.GpsMainActivity.java

/**
 * Allows user to send a GPX/KML file along with location, or location only
 * using a provider. 'Provider' means any application that can accept such
 * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth)
 *//* w  w  w . jav  a  2s . co  m*/
private void share() {

    try {

        final String locationOnly = getString(R.string.sharing_location_only);
        final File gpxFolder = new File(preferenceHelper.getGpsLoggerFolder());
        if (gpxFolder.exists()) {

            File[] enumeratedFiles = Files.fromFolder(gpxFolder);

            Arrays.sort(enumeratedFiles, new Comparator<File>() {
                public int compare(File f1, File f2) {
                    return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
                }
            });

            List<String> fileList = new ArrayList<>(enumeratedFiles.length);

            for (File f : enumeratedFiles) {
                fileList.add(f.getName());
            }

            fileList.add(0, locationOnly);
            final String[] files = fileList.toArray(new String[fileList.size()]);

            new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files)
                    .positiveText(R.string.ok)
                    .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {
                        @Override
                        public boolean onSelection(MaterialDialog materialDialog, Integer[] integers,
                                CharSequence[] charSequences) {
                            List<Integer> selectedItems = Arrays.asList(integers);

                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("*/*");

                            if (selectedItems.size() <= 0) {
                                return false;
                            }

                            if (selectedItems.contains(0)) {

                                intent.setType("text/plain");

                                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                                if (Session.hasValidLocation()) {
                                    String bodyText = getString(R.string.sharing_googlemaps_link,
                                            String.valueOf(Session.getCurrentLatitude()),
                                            String.valueOf(Session.getCurrentLongitude()));
                                    intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                                    intent.putExtra("sms_body", bodyText);
                                    startActivity(
                                            Intent.createChooser(intent, getString(R.string.sharing_via)));
                                }
                            } else {

                                intent.setAction(Intent.ACTION_SEND_MULTIPLE);
                                intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
                                intent.setType("*/*");

                                ArrayList<Uri> chosenFiles = new ArrayList<>();

                                for (Object path : selectedItems) {
                                    File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]);
                                    Uri uri = Uri.fromFile(file);
                                    chosenFiles.add(uri);
                                }

                                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles);
                                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
                            }
                            return true;
                        }
                    }).show();

        } else {
            Dialogs.alert(getString(R.string.sorry), getString(R.string.no_files_found), this);
        }
    } catch (Exception ex) {
        LOG.error("Sharing problem", ex);
    }
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

@SuppressWarnings("unchecked")
@Override//  www.jav  a 2 s . com
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    initViews();
    if (formLocation)
        queryLocation(true);

    if (savedState != null) {
        if (savedState.containsKey("tempfile"))
            tempFile = new File(savedState.getString("tempfile"));
        if (savedState.containsKey("target"))
            resolveTarget(savedState.getString("target"));
        if (savedState.containsKey("tempfiles"))
            tempFiles = savedState.getStringArrayList("tempfiles");
        if (savedState.containsKey("contents")) {
            contents = new ArrayList<Uri>();
            String[] carr = savedState.getStringArray("contents");
            for (String s : carr)
                contents.add(Uri.parse(s));
        }
    }

    postfix = "from <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>";

    Button uploadVisit = (Button) findViewById(R.id.upload_visit);
    if (passThrough || target == null)
        uploadVisit.setEnabled(false);
    else
        uploadVisit.setEnabled(true);

    /* populate data by getting STREAM parameter */
    Intent i = getIntent();
    Bundle b = i.getExtras();
    String action = i.getAction();

    if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) {
        called = true;

        if (i.hasExtra(Intent.EXTRA_STREAM)) {
            Object o = b.get(Intent.EXTRA_STREAM);

            /* quick and dirty. any better idea? */
            try {
                contents.add((Uri) o);
            } catch (Exception e1) {
                try {
                    contents = (ArrayList<Uri>) ((ArrayList<Uri>) o).clone();
                } catch (Exception e2) {
                }
            }

            boolean exceeded = false;
            if (contents.size() > 5) {
                exceeded = true;

                do {
                    contents.remove(5);
                } while (contents.size() > 5);
            }

            galleryChanged = true;

            updateImageButtons();
            resetThumbnails();
            updateGallery();

            if (exceeded)
                Toast.makeText(this,
                        " 5  . 5 ??? ? ?.",
                        Toast.LENGTH_LONG).show();
        }
        if (i.hasExtra(Intent.EXTRA_TEXT)) {
            ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TEXT));
        }
    } else if (action.equals("share")) {
        called = true;
        /* HTC web browser uses non-standard intent */

        ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TITLE));
    } else if (action.equals(Intent.ACTION_VIEW)) {
        Uri uri = i.getData();

        if (i.getCategories().contains(Intent.CATEGORY_BROWSABLE)) {
            passThrough = true;

            Pattern p = Pattern.compile("id=([\\-a-zA-Z0-9_]+)");
            Matcher m = p.matcher(uri.toString());

            if (m.find()) {
                resolveTarget(m.group(1));
            } else {
                passThrough = false;
            }

            if (uri.getHost().equals(Application.HOST_DCMYS)) {
                destination = Application.DESTINATION_DCMYS;
                postfix = "from dc.m.dcmys.kr w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>";
            } else if (uri.getHost().equals(Application.HOST_MOOLZO)) {
                destination = Application.DESTINATION_MOOLZO;
                postfix = "- From m.oolzo.com w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>";
            } else if (uri.getHost().equals(Application.HOST_DCINSIDE)) {
                destination = Application.DESTINATION_DCINSIDE;
            }

            setDefaultImage();
        }
    }

    reloadConfigurations();
}

From source file:de.baumann.browser.Browser_right.java

@SuppressLint("SetJavaScriptEnabled")
@Override/* w ww .java2  s.  c om*/
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 (id == R.id.action_search) {
        urlBar.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        helper_editText.showKeyboard(Browser_right.this, editText, 3, "", getString(R.string.app_search_hint));
    }

    if (id == R.id.action_history) {
        helper_main.switchToActivity(Browser_right.this, Popup_history.class, "", false);
    }

    if (id == R.id.action_search_chooseWebsite) {
        helper_editText.editText_searchWeb(editText, Browser_right.this);
    }

    if (id == R.id.action_pass) {
        helper_main.switchToActivity(Browser_right.this, Popup_pass.class, "", false);
        sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply();
        sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply();
    }

    if (id == R.id.action_toggle) {

        sharedPref.edit().putString("started", "yes").apply();

        if (Uri.parse(mWebView.getUrl()).getHost().length() == 0) {
            domain = getString(R.string.app_domain);
        } else {
            domain = Uri.parse(mWebView.getUrl()).getHost();
        }

        final String whiteList = sharedPref.getString("whiteList", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(Browser_right.this);
        View dialogView = View.inflate(Browser_right.this, R.layout.dialog_toggle, null);

        Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1);
        Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2);
        Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3);
        Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4);
        final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js);

        if (whiteList.contains(domain)) {
            whiteList_js.setImageResource(R.drawable.check_green);
        } else {
            whiteList_js.setImageResource(R.drawable.close_red);
        }
        if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) {
            sw_java.setChecked(true);
        } else {
            sw_java.setChecked(false);
        }
        if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) {
            sw_pictures.setChecked(true);
        } else {
            sw_pictures.setChecked(false);
        }
        if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) {
            sw_location.setChecked(true);
        } else {
            sw_location.setChecked(false);
        }
        if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) {
            sw_cookies.setChecked(true);
        } else {
            sw_cookies.setChecked(false);
        }

        whiteList_js.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (whiteList.contains(domain)) {
                    whiteList_js.setImageResource(R.drawable.close_red);
                    String removed = whiteList.replaceAll(domain, "");
                    sharedPref.edit().putString("whiteList", removed).apply();
                } else {
                    whiteList_js.setImageResource(R.drawable.check_green);
                    sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply();
                }
            }
        });
        sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply();
                    mWebView.getSettings().setJavaScriptEnabled(true);
                } else {
                    sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply();
                    mWebView.getSettings().setJavaScriptEnabled(false);
                }

            }
        });
        sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply();
                    mWebView.getSettings().setLoadsImagesAutomatically(true);
                } else {
                    sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply();
                    mWebView.getSettings().setLoadsImagesAutomatically(false);
                }

            }
        });
        sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply();
                    mWebView.getSettings().setGeolocationEnabled(true);
                    helper_main.grantPermissionsLoc(Browser_right.this);
                } else {
                    sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply();
                    mWebView.getSettings().setGeolocationEnabled(false);
                }

            }
        });
        sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply();
                    CookieManager cookieManager = CookieManager.getInstance();
                    cookieManager.setAcceptCookie(true);
                } else {
                    sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply();
                    CookieManager cookieManager = CookieManager.getInstance();
                    cookieManager.setAcceptCookie(false);
                }

            }
        });

        builder.setView(dialogView);
        builder.setTitle(R.string.menu_toggle_title);
        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                mWebView.reload();
            }
        });
        builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply();
                sharedPref.edit().putString("lastActivity", "browser_right").apply();
                helper_main.switchToActivity(Browser_right.this, Activity_settings.class, "", true);
            }
        });

        final AlertDialog dialog = builder.create();
        // Display the custom alert dialog on interface
        dialog.show();

    }

    if (id == R.id.menu_save_screenshot) {
        screenshot();
    }

    if (id == R.id.menu_save_bookmark) {
        urlBar.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        helper_editText.editText_saveBookmark(editText, Browser_right.this, mWebView);
    }

    if (id == R.id.menu_save_readLater) {
        DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this);
        db.open();
        if (db.isExist(mWebView.getUrl())) {
            Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show();
        } else {
            db.insert(helper_webView.getTitle(mWebView), mWebView.getUrl(), "", "", helper_main.createDate());
            Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show();
        }
    }

    if (id == R.id.menu_save_pass) {
        helper_editText.editText_savePass(Browser_right.this, mWebView, mWebView.getTitle(), mWebView.getUrl());
    }

    if (id == R.id.menu_createShortcut) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_VIEW);
        i.setClassName(Browser_right.this, "de.baumann.browser.Browser_left");
        i.setData(Uri.parse(mWebView.getUrl()));

        Intent shortcut = new Intent();
        shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
        shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle());
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
                .fromContext(Browser_right.this.getApplicationContext(), R.mipmap.ic_launcher));
        shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        Browser_right.this.sendBroadcast(shortcut);
        Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show();
    }

    if (id == R.id.menu_share_screenshot) {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("image/png");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        Uri bmpUri = Uri.fromFile(shareFile);
        sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot))));
    }

    if (id == R.id.menu_share_link) {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link))));
    }

    if (id == R.id.menu_share_link_copy) {
        String url = mWebView.getUrl();
        ClipboardManager clipboard = (ClipboardManager) Browser_right.this
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
        Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show();
    }

    if (id == R.id.action_downloads) {
        helper_main.switchToActivity(Browser_right.this, Popup_files.class, "", false);
    }

    if (id == R.id.action_search_go) {

        String text = editText.getText().toString();
        helper_webView.openURL(Browser_right.this, mWebView, editText);
        helper_editText.hideKeyboard(Browser_right.this, editText, 0, text,
                getString(R.string.app_search_hint));
        helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar);
        urlBar.setVisibility(View.VISIBLE);
        editText.setVisibility(View.GONE);
    }

    if (id == R.id.action_search_onSite) {
        urlBar.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        helper_editText.showKeyboard(Browser_right.this, editText, 1, "", getString(R.string.app_search_hint));
        helper_editText.editText_FocusChange_searchSite(editText, Browser_right.this);
        helper_editText.editText_searchSite(editText, Browser_right.this, mWebView, urlBar);
    }

    if (id == R.id.action_search_onSite_go) {

        String text = editText.getText().toString();

        if (text.startsWith(getString(R.string.app_search))) {
            helper_editText.editText_searchSite(editText, Browser_right.this, mWebView, urlBar);
        } else {
            mWebView.findAllAsync(text);
            helper_editText.hideKeyboard(Browser_right.this, editText, 1,
                    getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site));
        }
    }

    if (id == R.id.action_prev) {
        mWebView.findNext(false);
    }

    if (id == R.id.action_next) {
        mWebView.findNext(true);
    }

    if (id == R.id.action_cancel) {
        urlBar.setVisibility(View.VISIBLE);
        urlBar.setText(mWebView.getTitle());
        editText.setVisibility(View.GONE);
        helper_editText.editText_FocusChange(editText, Browser_right.this);
        helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar);
        helper_editText.hideKeyboard(Browser_right.this, editText, 0, mWebView.getTitle(),
                getString(R.string.app_search_hint));
    }

    if (id == R.id.action_save_bookmark) {
        helper_editText.editText_saveBookmark_save(editText, Browser_right.this, mWebView);
        urlBar.setVisibility(View.VISIBLE);
        editText.setVisibility(View.GONE);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java

private boolean archiveWalletBackup(@Nonnull final File file) {
    Uri shareableUri = null;/*from www  . ja  v a 2 s. c  o  m*/
    try {
        shareableUri = FileProvider.getUriForFile(this, Constants.FILE_PROVIDER_AUTHORITY, file);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Backup file cannot be shared", e);
    }

    log.info("Shareable URI: {}", shareableUri);

    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_keys_dialog_mail_subject));
    intent.putExtra(Intent.EXTRA_TEXT,
            getString(R.string.export_keys_dialog_mail_text) + "\n\n"
                    + String.format(Constants.WEBMARKET_APP_URL, getPackageName()) + "\n\n"
                    + Constants.SOURCE_URL + '\n');
    intent.setType(Constants.MIMETYPE_WALLET_BACKUP);
    intent.putExtra(Intent.EXTRA_STREAM, shareableUri);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        startActivity(Intent.createChooser(intent, getString(R.string.export_keys_dialog_mail_intent_chooser)));
        log.info("invoked chooser for archiving wallet backup");
        return true;
    } catch (final Exception x) {
        longToast(R.string.export_keys_dialog_mail_intent_failed);
        log.error("archiving wallet backup failed", x);
        return false;
    }
}

From source file:de.baumann.browser.Browser_left.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from w  w  w  .  j a  v a  2s  .  c  o  m*/
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 (id == R.id.action_search) {
        urlBar.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        helper_editText.showKeyboard(Browser_left.this, editText, 3, "", getString(R.string.app_search_hint));
    }

    if (id == R.id.action_history) {
        helper_main.switchToActivity(Browser_left.this, Popup_history.class, "", false);
    }

    if (id == R.id.action_search_chooseWebsite) {
        helper_editText.editText_searchWeb(editText, Browser_left.this);
    }

    if (id == R.id.action_pass) {
        helper_main.switchToActivity(Browser_left.this, Popup_pass.class, "", false);
        sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply();
        sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply();
    }

    if (id == R.id.action_toggle) {

        sharedPref.edit().putString("started", "yes").apply();

        if (Uri.parse(mWebView.getUrl()).getHost().length() == 0) {
            domain = getString(R.string.app_domain);
        } else {
            domain = Uri.parse(mWebView.getUrl()).getHost();
        }

        final String whiteList = sharedPref.getString("whiteList", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(Browser_left.this);
        View dialogView = View.inflate(Browser_left.this, R.layout.dialog_toggle, null);

        Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1);
        Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2);
        Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3);
        Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4);
        final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js);

        if (whiteList.contains(domain)) {
            whiteList_js.setImageResource(R.drawable.check_green);
        } else {
            whiteList_js.setImageResource(R.drawable.close_red);
        }
        if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) {
            sw_java.setChecked(true);
        } else {
            sw_java.setChecked(false);
        }
        if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) {
            sw_pictures.setChecked(true);
        } else {
            sw_pictures.setChecked(false);
        }
        if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) {
            sw_location.setChecked(true);
        } else {
            sw_location.setChecked(false);
        }
        if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) {
            sw_cookies.setChecked(true);
        } else {
            sw_cookies.setChecked(false);
        }

        whiteList_js.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (whiteList.contains(domain)) {
                    whiteList_js.setImageResource(R.drawable.close_red);
                    String removed = whiteList.replaceAll(domain, "");
                    sharedPref.edit().putString("whiteList", removed).apply();
                } else {
                    whiteList_js.setImageResource(R.drawable.check_green);
                    sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply();
                }
            }
        });
        sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply();
                    mWebView.getSettings().setJavaScriptEnabled(true);
                } else {
                    sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply();
                    mWebView.getSettings().setJavaScriptEnabled(false);
                }

            }
        });
        sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply();
                    mWebView.getSettings().setLoadsImagesAutomatically(true);
                } else {
                    sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply();
                    mWebView.getSettings().setLoadsImagesAutomatically(false);
                }

            }
        });
        sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply();
                    mWebView.getSettings().setGeolocationEnabled(true);
                    helper_main.grantPermissionsLoc(Browser_left.this);
                } else {
                    sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply();
                    mWebView.getSettings().setGeolocationEnabled(false);
                }

            }
        });
        sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply();
                    CookieManager cookieManager = CookieManager.getInstance();
                    cookieManager.setAcceptCookie(true);
                } else {
                    sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply();
                    CookieManager cookieManager = CookieManager.getInstance();
                    cookieManager.setAcceptCookie(false);
                }

            }
        });

        builder.setView(dialogView);
        builder.setTitle(R.string.menu_toggle_title);
        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                mWebView.reload();
            }
        });
        builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply();
                sharedPref.edit().putString("lastActivity", "browser_left").apply();
                helper_main.switchToActivity(Browser_left.this, Activity_settings.class, "", true);
            }
        });

        final AlertDialog dialog = builder.create();
        // Display the custom alert dialog on interface
        dialog.show();

    }

    if (id == R.id.menu_save_screenshot) {
        screenshot();
    }

    if (id == R.id.menu_save_bookmark) {
        urlBar.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        helper_editText.editText_saveBookmark(editText, Browser_left.this, mWebView);
    }

    if (id == R.id.menu_save_readLater) {
        DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this);
        db.open();
        if (db.isExist(mWebView.getUrl())) {
            Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show();
        } else {
            db.insert(helper_webView.getTitle(mWebView), mWebView.getUrl(), "", "", helper_main.createDate());
            Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show();
        }
    }

    if (id == R.id.menu_save_pass) {
        helper_editText.editText_savePass(Browser_left.this, mWebView, mWebView.getTitle(), mWebView.getUrl());
    }

    if (id == R.id.menu_createShortcut) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_VIEW);
        i.setClassName(Browser_left.this, "de.baumann.browser.Browser_left");
        i.setData(Uri.parse(mWebView.getUrl()));

        Intent shortcut = new Intent();
        shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
        shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle());
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
                .fromContext(Browser_left.this.getApplicationContext(), R.mipmap.ic_launcher));
        shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        Browser_left.this.sendBroadcast(shortcut);
        Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show();
    }

    if (id == R.id.menu_share_screenshot) {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("image/png");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        Uri bmpUri = Uri.fromFile(shareFile);
        sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot))));
    }

    if (id == R.id.menu_share_link) {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link))));
    }

    if (id == R.id.menu_share_link_copy) {
        String url = mWebView.getUrl();
        ClipboardManager clipboard = (ClipboardManager) Browser_left.this
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
        Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show();
    }

    if (id == R.id.action_downloads) {
        helper_main.switchToActivity(Browser_left.this, Popup_files.class, "", false);
    }

    if (id == R.id.action_search_go) {

        String text = editText.getText().toString();
        helper_webView.openURL(Browser_left.this, mWebView, editText);
        helper_editText.hideKeyboard(Browser_left.this, editText, 0, text, getString(R.string.app_search_hint));
        helper_editText.editText_EditorAction(editText, Browser_left.this, mWebView, urlBar);
        urlBar.setVisibility(View.VISIBLE);
        editText.setVisibility(View.GONE);
    }

    if (id == R.id.action_search_onSite) {
        urlBar.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        helper_editText.showKeyboard(Browser_left.this, editText, 1, "", getString(R.string.app_search_hint));
        helper_editText.editText_FocusChange_searchSite(editText, Browser_left.this);
        helper_editText.editText_searchSite(editText, Browser_left.this, mWebView, urlBar);
    }

    if (id == R.id.action_search_onSite_go) {

        String text = editText.getText().toString();

        if (text.startsWith(getString(R.string.app_search))) {
            helper_editText.editText_searchSite(editText, Browser_left.this, mWebView, urlBar);
        } else {
            mWebView.findAllAsync(text);
            helper_editText.hideKeyboard(Browser_left.this, editText, 1,
                    getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site));
        }
    }

    if (id == R.id.action_prev) {
        mWebView.findNext(false);
    }

    if (id == R.id.action_next) {
        mWebView.findNext(true);
    }

    if (id == R.id.action_cancel) {
        urlBar.setVisibility(View.VISIBLE);
        urlBar.setText(mWebView.getTitle());
        editText.setVisibility(View.GONE);
        helper_editText.editText_FocusChange(editText, Browser_left.this);
        helper_editText.editText_EditorAction(editText, Browser_left.this, mWebView, urlBar);
        helper_editText.hideKeyboard(Browser_left.this, editText, 0, mWebView.getTitle(),
                getString(R.string.app_search_hint));
    }

    if (id == R.id.action_save_bookmark) {
        helper_editText.editText_saveBookmark_save(editText, Browser_left.this, mWebView);
        urlBar.setVisibility(View.VISIBLE);
        editText.setVisibility(View.GONE);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

/**
 * Share all contacts that are currently selected. This method is pretty inefficient for
 * handling large numbers of contacts. I don't expect this to be a problem.
 *///  www  . j  av a  2 s  .c o  m
private void shareSelectedContacts() {
    final StringBuilder uriListBuilder = new StringBuilder();
    for (Long contactId : getSelectedContactIds()) {
        final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
        final Uri lookupUri = ContactsContract.Contacts.getLookupUri(getContext().getContentResolver(),
                contactUri);
        if (lookupUri == null) {
            continue;
        }
        final List<String> pathSegments = lookupUri.getPathSegments();
        if (pathSegments.size() < 2) {
            continue;
        }
        final String lookupKey = pathSegments.get(pathSegments.size() - 2);
        if (uriListBuilder.length() > 0) {
            uriListBuilder.append(':');
        }
        uriListBuilder.append(Uri.encode(lookupKey));
    }
    if (uriListBuilder.length() == 0) {
        return;
    }
    final Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_MULTI_VCARD_URI,
            Uri.encode(uriListBuilder.toString()));
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    try {
        startActivityForResult(Intent.createChooser(intent, getResources()
                .getQuantityString(R.plurals.title_share_via, /* quantity */ getSelectedContactIds().size())),
                ACTIVITY_REQUEST_CODE_SHARE);
    } catch (final ActivityNotFoundException ex) {
        Toast.makeText(getContext(), R.string.share_error, Toast.LENGTH_SHORT).show();
    }
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private boolean handleSendToAction() {
    Intent intent = getIntent();//ww w.  j  a  v a 2  s .c o m
    String action = intent.getAction();
    long filesize = 0;

    if (action != null) {
        if (action.equals(Intent.ACTION_SEND_MULTIPLE)) {

            showErrorExit(R.string.error_MultipleSendNotSupported);
            return false;

        } else if (action.equals(Intent.ACTION_SEND)) {
            DraftData d = DraftData.INSTANCE;

            d.setMsgHash(null);

            String type = intent.getType();
            Uri stream = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);

            // if this is from a share menu
            try {
                // Get resource path from intent caller
                if (Intent.ACTION_SEND.equals(action)) {
                    if (stream != null) {
                        filesize = getOutStreamSizeAndData(stream, type);
                    } else if (!TextUtils.isEmpty(extra_text)) {
                        filesize = extra_text.length();
                        if (filesize <= SafeSlingerConfig.MAX_TEXTMESSAGE) {
                            d.removeFile();
                            d.setText(extra_text.toString());
                        } else {
                            d.setFileType("text/plain");
                            final byte[] textBytes = extra_text.toString().getBytes();
                            d.setFileData(textBytes);
                            d.setFileSize(textBytes.length);
                            SimpleDateFormat sdf = new SimpleDateFormat(SafeSlingerConfig.DATETIME_FILENAME,
                                    Locale.US);
                            d.setFileName(sdf.format(new Date()) + ".txt");
                            d.removeText();
                        }
                    }
                }

                if (filesize <= 0) {
                    showErrorExit(R.string.error_CannotSendEmptyFile);
                    return false;
                }
                if (filesize > SafeSlingerConfig.MAX_FILEBYTES) {
                    showErrorExit(String.format(getString(R.string.error_CannotSendFilesOver),
                            SafeSlingerConfig.MAX_FILEBYTES));
                    return false;
                }
            } catch (IOException e) {
                showErrorExit(e);
                return false;
            } catch (OutOfMemoryError e) {
                showErrorExit(R.string.error_OutOfMemoryError);
                return false;
            }
        }
    }
    return true;
}