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.frankegan.sqrshare.MainActivity.java

/**
 * Shares the image currently being displayed by the {@link android.widget.ImageView}.
 *//*  w  w w  . j ava  2s . co m*/
private void sharePicture() {
    Uri uri = pic_fragment.getPictureUri();
    if (uri != null) {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
    }
}

From source file:de.hska.iam.presentationapp.activities.ChooseMediaActivity.java

public void shareDate(String share) {

    Intent shareDataIntent = new Intent(Intent.ACTION_SEND);
    shareDataIntent.putExtra(Intent.EXTRA_STREAM, uri);

    if (UriUtils.isImage(uri)) {

        shareDataIntent.setType("image/*");
        startActivity(Intent.createChooser(shareDataIntent, "Teilen mit "));

    } else if (UriUtils.isPdf(uri)) {

        shareDataIntent.setType("pdf/*");
        startActivity(Intent.createChooser(shareDataIntent, "Teilen mit "));

    } else if (UriUtils.isVideo(uri)) {

        shareDataIntent.setType("video/*");
        startActivity(Intent.createChooser(shareDataIntent, "Teilen mit "));

    }/*  w w  w . j  a  v a  2  s. co  m*/
}

From source file:com.darizotas.metadatastrip.FileDetailFragment.java

/**
 * Creates the Share Intent that contains the 
 * @param container Metadata container./*from w w w.  j  a  va 2s.  co m*/
 * @return Intent for sharing.
 */
private Intent getShareIntent(MetaDataContainer container) {
    Intent intent = new Intent(Intent.ACTION_SEND);

    intent.putExtra(Intent.EXTRA_SUBJECT, "[" + getResources().getString(R.string.app_name) + "] "
            + getResources().getString(R.string.share_subject) + " " + container.getFileName());
    intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_text) + " "
            + DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()));

    try {
        // http://stackoverflow.com/questions/3272534/what-content-type-value-should-i-send-for-my-xml-sitemap
        // http://www.grauw.nl/blog/entry/489
        intent.setType("application/xml");
        //https://developer.android.com/training/sharing/send.html#send-binary-content
        //https://developer.android.com/reference/android/support/v4/content/FileProvider.html
        mStripFile = getMetadataFile(container);
        Uri uri = FileProvider.getUriForFile(getActivity(), "com.darizotas.metadatastrip", mStripFile);
        intent.putExtra(Intent.EXTRA_STREAM, uri);

    } catch (IllegalArgumentException e) {
        // Invalidates the intent.
        intent.setType(null);
    }
    return intent;
}

From source file:com.galois.qrstream.MainActivity.java

private Job buildJobFromIntent(Intent intent) throws IllegalArgumentException {
    String type = intent.getType();
    Bundle extras = intent.getExtras();//www  .  ja  va 2 s  . c o m
    Log.d(Constants.APP_TAG, "** received type " + type);

    String name = "";
    byte[] bytes = null;

    Uri dataUrl = (Uri) intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
    if (dataUrl != null) {
        name = getNameFromURI(dataUrl);
        if (dataUrl.getScheme().equals("content") || dataUrl.getScheme().equals("file")) {
            try {
                bytes = readFileUri(dataUrl);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            Log.d(Constants.APP_TAG, "unsupported url: " + dataUrl);
        }
    } else {
        // fall back to content in extras (mime type dependent)
        if (type.equals("text/plain")) {
            String subject = extras.getString(Intent.EXTRA_SUBJECT);
            String text = extras.getString(Intent.EXTRA_TEXT);
            if (subject == null) {
                bytes = text.getBytes();
            } else {
                bytes = encodeSubjectAndText(subject, text);
                type = Constants.MIME_TYPE_TEXT_NOTE;
            }
        }
    }
    return new Job(name, bytes, type);
}

From source file:com.gmail.altakey.lucene.AsyncImageLoader.java

private InputStream read(ProgressReportingInputStream.ProgressListener listener) throws FileNotFoundException {
    final Context context = this.view.getContext();

    if (Intent.ACTION_SEND.equals(this.intent.getAction())) {
        final Bundle extras = this.intent.getExtras();
        if (extras.containsKey(Intent.EXTRA_STREAM))
            return new ProgressReportingInputStream(context.getContentResolver()
                    .openInputStream((Uri) extras.getParcelable(Intent.EXTRA_STREAM)), listener);
        if (extras.containsKey(Intent.EXTRA_TEXT)) {
            try {
                final HttpGet req = new HttpGet(extras.getCharSequence(Intent.EXTRA_TEXT).toString());
                return new ProgressReportingInputStream(this.httpClient.execute(req).getEntity().getContent(),
                        listener);//ww w. j av a  2  s  .c o m
            } catch (IllegalArgumentException e) {
                return null;
            } catch (IOException e) {
                return null;
            }
        }
    }

    if (Intent.ACTION_VIEW.equals(this.intent.getAction()))
        return new ProgressReportingInputStream(
                context.getContentResolver().openInputStream(this.intent.getData()), listener);

    return null;
}

From source file:com.lvfq.rabbit.fragment.SettingFragment.java

private void onShare(Bitmap bitmap) {
    if (bitmap != null && isExternalStorageReadable() && isExternalStorageWritable()) {
        Uri imageUri = null;//w  w w  . j a  v  a2s  .  c o m
        try {
            SaveImage(bitmap);
            String root = Environment.getExternalStorageDirectory().toString();
            File shareImage = new File(
                    root + "/" + getActivity().getApplication().getPackageName() + "/images/share_qr.png");
            imageUri = Uri.fromFile(shareImage);
            Log.d(TAG, imageUri.toString());
        } catch (Exception e) {
            imageUri = null;
            e.printStackTrace();
        }
        if (imageUri != null) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
            shareIntent.setType("image/png");
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_app)));
        }
    } else {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, "-??app " + getString(R.string.share_apk));
        shareIntent.setType("text/plain");
        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_app)));
    }
    synchronized (canShare) {
        canShare = true;
    }
}

From source file:it.uniroma3.android.gpstracklogger.adapters.AdapterTrack.java

private void sendMail(int position) {
    Track track = Session.getController().getImportedTracks().get(position);
    final Intent intent = new Intent(Intent.ACTION_SEND);

    intent.setType("*/*");
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_SUBJECT, "Traccia: " + track.getName());

    ArrayList<Uri> chosenFile = new ArrayList<>();
    String path = track.getPath();
    File file = new File(path);
    Uri uri = null;//from ww w . j  a va2 s. c om
    if (path.contains(AppSettings.getDirectory()))
        uri = FileProvider.getUriForFile(activity, "it.uniroma3.android.gpstracklogger.GPSMainActivity", file);
    else
        uri = Uri.fromFile(file);

    chosenFile.add(uri);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFile);
    activity.startActivity(Intent.createChooser(intent, "Condividi via..."));
}

From source file:com.agateau.equiv.ui.Kernel.java

public void shareCustomProductList(Context context) {
    File file = context.getFileStreamPath(CUSTOM_PRODUCTS_CSV);
    Uri contentUri = FileProvider.getUriForFile(context, "com.agateau.equiv.fileprovider", file);
    final Resources res = context.getResources();

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.CUSTOM_PRODUCTS_EMAIL });
    intent.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.share_email_subject));
    intent.putExtra(Intent.EXTRA_STREAM, contentUri);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    context.startActivity(Intent.createChooser(intent, res.getString(R.string.share_via)));
}

From source file:com.richtodd.android.quiltdesign.app.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.menu_settings: {
        Intent intent = new Intent(this, MainPreferenceActivity.class);
        startActivity(intent);/*from w  w  w . jav  a  2  s  .c  o m*/

        return true;
    }
    case R.id.menu_about: {
        TextDialogFragment dialog = TextDialogFragment.create("About Quilt Design", getString(R.string.about),
                "Close");
        dialog.show(getFragmentManager(), null);

        return true;
    }
    case R.id.menu_help: {
        // Intent intent = new Intent(this, BrowserActivity.class);
        // intent.putExtra(BrowserActivity.ARG_URL,
        // "http://quiltdesign.richtodd.com");

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://quiltdesign.richtodd.com"));
        startActivity(intent);

        return true;
    }
    case R.id.menu_backup: {
        Uri uriFile;
        try {
            uriFile = saveRepository();

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, uriFile);
            intent.setType("application/vnd.richtodd.quiltdesign");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            startActivity(Intent.createChooser(intent, "Backup"));

        } catch (RepositoryException e) {
            Handle.asRuntimeError(e);
        }

        return true;
    }
    case R.id.menu_loadSamples: {

        SampleLoaderTask task = new SampleLoaderTask();
        setSampleLoaderTask(task);
        task.execute(this);

        return true;
    }
    }

    return super.onOptionsItemSelected(item);
}

From source file:ooo.oxo.mr.ViewerActivity.java

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

    binding = DataBindingUtil.setContentView(this, R.layout.viewer_activity);

    setTitle(null);/*from  w  w w . j  a v  a  2 s . co  m*/

    binding.toolbar.setNavigationOnClickListener(v -> supportFinishAfterTransition());
    binding.toolbar.inflateMenu(R.menu.viewer);

    binding.puller.setCallback(this);

    supportPostponeEnterTransition();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getEnterTransition().addListener(new SimpleTransitionListener() {
            @Override
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            public void onTransitionEnd(Transition transition) {
                getWindow().getEnterTransition().removeListener(this);
                fadeIn();
            }
        });
    } else {
        fadeIn();
    }

    background = new ColorDrawable(Color.BLACK);
    binding.getRoot().setBackground(background);

    adapter = new Adapter();

    binding.pager.setAdapter(adapter);
    binding.pager.setCurrentItem(getIntent().getIntExtra("index", 0));
    binding.pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == ViewPager.SCROLL_STATE_DRAGGING) {
                fadeOut();
            }
        }
    });

    listener = new ObservableListPagerAdapterCallback(adapter);
    images.addOnListChangedCallback(listener);

    setEnterSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            Image image = images.get(binding.pager.getCurrentItem());
            sharedElements.clear();
            sharedElements.put(String.format("%s.image", image.getObjectId()), getCurrent().getSharedElement());
        }
    });

    menuItemClicks(R.id.share).compose(bindToLifecycle())
            .compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE))
            .map(avoid -> getCurrentImage())
            .doOnNext(image -> MobclickAgent.onEvent(this, "share", image.getObjectId()))
            .observeOn(Schedulers.io()).flatMap(this::saveIfNeeded).observeOn(AndroidSchedulers.mainThread())
            .doOnNext(this::notifyMediaScanning).map(Uri::fromFile).retry().subscribe(uri -> {
                final Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("image/jpeg");
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(intent, getString(R.string.share_title)));
            });

    menuItemClicks(R.id.save).compose(bindToLifecycle())
            .compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE))
            .map(avoid -> getCurrentImage())
            .doOnNext(image -> MobclickAgent.onEvent(this, "save", image.getObjectId()))
            .observeOn(Schedulers.io()).flatMap(this::saveIfNeeded).observeOn(AndroidSchedulers.mainThread())
            .doOnNext(this::notifyMediaScanning).retry().subscribe(file -> {
                ToastUtil.shorts(this, R.string.save_success, file.getPath());
            });

    final WallpaperManager wm = WallpaperManager.getInstance(this);

    menuItemClicks(R.id.set_wallpaper).compose(bindToLifecycle()).map(avoid -> getCurrentImage())
            .doOnNext(image -> MobclickAgent.onEvent(this, "set_wallpaper", image.getObjectId()))
            .observeOn(Schedulers.io()).flatMap(this::download).observeOn(AndroidSchedulers.mainThread())
            .map(file -> FileProvider.getUriForFile(this, AUTHORITY_IMAGES, file)).retry().subscribe(uri -> {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                    startActivity(wm.getCropAndSetWallpaperIntent(uri));
                } else {
                    try {
                        wm.setStream(getContentResolver().openInputStream(uri));
                        ToastUtil.shorts(this, R.string.set_wallpaper_success);
                    } catch (IOException e) {
                        Log.e(TAG, "Failed to set wallpaper", e);
                        ToastUtil.shorts(this, e.getMessage(), e);
                    }
                }
            });
}