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:me.xiaopan.android.spear.sample.fragment.DetailFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button_detail_share:
        disableSingleTap = true;//from  ww  w . j av a  2s  . c  o  m
        File imageFile = getImageFile(uris.get(viewPager.getCurrentItem()), "");
        if (imageFile != null) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
            intent.setType("image/" + parseFileType(imageFile.getName()));
            List<ResolveInfo> infoList = getActivity().getPackageManager().queryIntentActivities(intent, 0);
            if (infoList != null && !infoList.isEmpty()) {
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), "APP", Toast.LENGTH_LONG)
                        .show();
            }
        }
        break;
    case R.id.button_detail_applyWallpaper:
        disableSingleTap = true;
        File imageFile2 = getImageFile(uris.get(viewPager.getCurrentItem()), "?");
        if (imageFile2 != null) {
            new ApplyWallpaperAsyncTask(getActivity(), imageFile2) {
                @Override
                protected void onPostExecute(Boolean aBoolean) {
                    if (getActivity() != null) {
                        Toast.makeText(getActivity(), aBoolean ? "??" : "?",
                                Toast.LENGTH_LONG).show();
                    }
                }
            }.execute(0);
        }
        break;
    case R.id.button_detail_play:
        disableSingleTap = true;
        viewPagerPlayer.start();
        toggleToolbarVisibleState();
        break;
    case R.id.button_detail_save:
        disableSingleTap = true;
        String currentUrl = uris.get(viewPager.getCurrentItem());
        if (currentUrl == null || "".equals(currentUrl.trim())) {
            Toast.makeText(getActivity(),
                    "??URL",
                    Toast.LENGTH_LONG).show();
        } else if (currentUrl.startsWith("http://") || currentUrl.startsWith("https://")) {
            File imageFile3 = Spear.with(getActivity()).getConfiguration().getDiskCache()
                    .getCacheFileByUri(currentUrl);
            if (imageFile3 == null) {
                Toast.makeText(getActivity(), "???",
                        Toast.LENGTH_LONG).show();
            } else {
                new SaveImageAsyncTask(getActivity(), imageFile3).execute("");
            }
        } else if (currentUrl.startsWith("/")) {
            Toast.makeText(getActivity(), "??", Toast.LENGTH_LONG)
                    .show();
        } else {
            Toast.makeText(getActivity(), "URL " + currentUrl, Toast.LENGTH_LONG)
                    .show();
        }
        break;
    }
}

From source file:com.github.dfa.diaspora_android.ui.ContextMenuWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    HitTestResult result = getHitTestResult();

    MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            HitTestResult result = getHitTestResult();
            String url = result.getExtra();
            switch (item.getItemId()) {
            //Save image to external memory
            case ID_SAVE_IMAGE: {
                boolean writeToStoragePermitted = true;
                if (android.os.Build.VERSION.SDK_INT >= 23) {
                    int hasWRITE_EXTERNAL_STORAGE = parentActivity
                            .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                        writeToStoragePermitted = false;
                        if (!parentActivity.shouldShowRequestPermissionRationale(
                                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                            new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                    .setPositiveButton(context.getText(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (android.os.Build.VERSION.SDK_INT >= 23)
                                                        parentActivity.requestPermissions(new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                }
                                            })
                                    .setNegativeButton(context.getText(android.R.string.no), null).show();
                        }// ww  w .  j a va2s .c o m
                        parentActivity.requestPermissions(
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                    }
                }
                if (writeToStoragePermitted) {
                    if (url != null) {
                        Uri source = Uri.parse(url);
                        DownloadManager.Request request = new DownloadManager.Request(source);
                        File destinationFile = new File(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        request.setDestinationUri(Uri.fromFile(destinationFile));
                        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
                        Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location)
                                + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    }
                }
            }
                break;

            case ID_SHARE_IMAGE:
                if (url != null) {
                    boolean writeToStoragePermitted = true;
                    if (android.os.Build.VERSION.SDK_INT >= 23) {
                        int hasWRITE_EXTERNAL_STORAGE = parentActivity
                                .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                            writeToStoragePermitted = false;
                            if (!parentActivity.shouldShowRequestPermissionRationale(
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                        .setPositiveButton(context.getText(android.R.string.yes),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        if (android.os.Build.VERSION.SDK_INT >= 23)
                                                            parentActivity.requestPermissions(new String[] {
                                                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                    MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                    }
                                                })
                                        .setNegativeButton(context.getText(android.R.string.no), null).show();
                            } else {
                                parentActivity.requestPermissions(
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                            }
                        }
                    }
                    if (writeToStoragePermitted) {
                        final Uri local = Uri.parse(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        new ImageDownloadTask(null, local.getPath()) {
                            @Override
                            protected void onPostExecute(Bitmap result) {
                                Uri myUri = Uri.fromFile(new File(local.getPath()));
                                Intent sharingIntent = new Intent();
                                sharingIntent.setAction(Intent.ACTION_SEND);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
                                sharingIntent.setType("image/png");
                                sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                context.startActivity(Intent.createChooser(sharingIntent,
                                        getResources().getString(R.string.action_share_dotdotdot)));
                            }
                        }.execute(url);
                    }
                } else {
                    Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
                }

                break;

            case ID_IMAGE_EXTERNAL_BROWSER:
                if (url != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    context.startActivity(intent);
                }
                break;

            //Copy url to clipboard
            case ID_COPY_LINK:
                if (url != null) {
                    ClipboardManager clipboard = (ClipboardManager) context
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
                    Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            //Try to share link to other apps
            case ID_SHARE_LINK:
                if (url != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, url);
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent,
                            getResources().getText(R.string.context_menu_share_link)));
                }
                break;
            }
            return true;
        }
    };

    //Build context menu
    if (result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        // Menu options for an image.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0,
                context.getString(R.string.context_menu_open_external_browser))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image))
                .setOnMenuItemClickListener(handler);
    } else if (result.getType() == HitTestResult.ANCHOR_TYPE
            || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        // Menu options for a hyperlink.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link))
                .setOnMenuItemClickListener(handler);
    }
}

From source file:com.github.dfa.diaspora_android.web.ContextMenuWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    HitTestResult result = getHitTestResult();

    MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            HitTestResult result = getHitTestResult();
            String url = result.getExtra();
            switch (item.getItemId()) {
            //Save image to external memory
            case ID_SAVE_IMAGE: {
                boolean writeToStoragePermitted = true;
                if (android.os.Build.VERSION.SDK_INT >= 23) {
                    int hasWRITE_EXTERNAL_STORAGE = parentActivity
                            .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                        writeToStoragePermitted = false;
                        if (!parentActivity.shouldShowRequestPermissionRationale(
                                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                            new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                    .setPositiveButton(context.getText(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (android.os.Build.VERSION.SDK_INT >= 23)
                                                        parentActivity.requestPermissions(new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                }
                                            })
                                    .setNegativeButton(context.getText(android.R.string.no), null).show();
                        }//  w  ww . j a v a 2s. c  o  m
                        parentActivity.requestPermissions(
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                    }
                }
                if (writeToStoragePermitted) {
                    if (url != null) {
                        Uri source = Uri.parse(url);
                        DownloadManager.Request request = new DownloadManager.Request(source);
                        File destinationFile = new File(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        request.setDestinationUri(Uri.fromFile(destinationFile));
                        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);

                        Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location)
                                + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    }
                }
            }
                break;

            case ID_SHARE_IMAGE:
                if (url != null) {
                    boolean writeToStoragePermitted = true;
                    if (android.os.Build.VERSION.SDK_INT >= 23) {
                        int hasWRITE_EXTERNAL_STORAGE = parentActivity
                                .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                            writeToStoragePermitted = false;
                            if (!parentActivity.shouldShowRequestPermissionRationale(
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                        .setPositiveButton(context.getText(android.R.string.yes),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        if (android.os.Build.VERSION.SDK_INT >= 23)
                                                            parentActivity.requestPermissions(new String[] {
                                                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                    MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                    }
                                                })
                                        .setNegativeButton(context.getText(android.R.string.no), null).show();
                            } else {
                                parentActivity.requestPermissions(
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                            }
                        }
                    }
                    if (writeToStoragePermitted) {
                        final Uri local = Uri.parse(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        new ImageDownloadTask(null, local.getPath()) {
                            @Override
                            protected void onPostExecute(Bitmap result) {
                                Uri myUri = Uri.fromFile(new File(local.getPath()));
                                Intent sharingIntent = new Intent();
                                sharingIntent.setAction(Intent.ACTION_SEND);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
                                sharingIntent.setType("image/png");
                                sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                context.startActivity(Intent.createChooser(sharingIntent,
                                        getResources().getString(R.string.action_share_dotdotdot)));
                            }
                        }.execute(url);
                    }
                } else {
                    Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
                }

                break;

            case ID_IMAGE_EXTERNAL_BROWSER:
                if (url != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    context.startActivity(intent);
                }
                break;

            //Copy url to clipboard
            case ID_COPY_LINK:
                if (url != null) {
                    ClipboardManager clipboard = (ClipboardManager) context
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
                    Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            //Try to share link to other apps
            case ID_SHARE_LINK:
                if (url != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, url);
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent,
                            getResources().getText(R.string.context_menu_share_link)));
                }
                break;
            }
            return true;
        }
    };

    //Build context menu
    if (result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        // Menu options for an image.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0,
                context.getString(R.string.context_menu_open_external_browser))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image))
                .setOnMenuItemClickListener(handler);
    } else if (result.getType() == HitTestResult.ANCHOR_TYPE
            || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        // Menu options for a hyperlink.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link))
                .setOnMenuItemClickListener(handler);
    }
}

From source file:nirwan.cordova.plugin.printer.Printer.java

private void loadContentAsBitmapIntoPrintController(String content, final Intent intent) {
    Activity ctx = cordova.getActivity();
    final WebView page = new WebView(ctx);
    final Printer self = this;

    page.setVisibility(View.INVISIBLE);
    page.getSettings().setJavaScriptEnabled(false);

    page.setWebViewClient(new WebViewClient() {
        @Override//w w w. j a va2s.  co  m
        public void onPageFinished(final WebView page, String url) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bitmap screenshot = self.takeScreenshot(page);
                    File tmpFile = self.saveScreenshotToTmpFile(screenshot);
                    ViewGroup vg = (ViewGroup) (page.getParent());

                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile));

                    vg.removeView(page);
                }
            }, 1000);
        }
    });

    //Set base URI to the assets/www folder
    String baseURL = webView.getUrl();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1);

    ctx.addContentView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    page.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null);
}

From source file:com.dm.material.dashboard.candybar.helpers.IconsHelper.java

public static void selectIcon(@NonNull Context context, int action, Icon icon) {
    if (action == IntentHelper.ICON_PICKER) {
        Intent intent = new Intent();
        Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" + icon.getRes(),
                ImageConfig.getRawImageOptions().build());

        intent.putExtra("icon", bitmap);
        ((AppCompatActivity) context).setResult(bitmap != null ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
                intent);/*from  w ww  . jav  a2 s. c  om*/
        ((AppCompatActivity) context).finish();
    } else if (action == IntentHelper.IMAGE_PICKER) {
        Intent intent = new Intent();
        Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" + icon.getRes(),
                ImageConfig.getRawImageOptions().build());
        if (bitmap != null) {
            File file = new File(context.getCacheDir(), icon.getTitle() + ".png");
            FileOutputStream outStream;
            try {
                outStream = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                outStream.flush();
                outStream.close();

                Uri uri = FileHelper.getUriFromFile(context, context.getPackageName(), file);
                if (uri == null)
                    uri = Uri.fromFile(file);
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                intent.setData(uri);
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } catch (Exception | OutOfMemoryError e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
            intent.putExtra("return-data", false);
        }
        ((AppCompatActivity) context).setResult(bitmap != null ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
                intent);
        ((AppCompatActivity) context).finish();
    } else {
        IconPreviewFragment.showIconPreview(((AppCompatActivity) context).getSupportFragmentManager(),
                icon.getTitle(), icon.getRes());
    }
}

From source file:com.android.mail.browse.AttachmentActionHandler.java

public void shareAttachment() {
    if (mAttachment.contentUri == null) {
        return;/* w ww .j  ava2s. co  m*/
    }

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    final Uri uri = Utils.normalizeUri(mAttachment.contentUri);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.setType(Utils.normalizeMimeType(mAttachment.getContentType()));

    try {
        mContext.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // couldn't find activity for SEND intent
        LogUtils.e(LOG_TAG, "Couldn't find Activity for intent", e);
    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.camera.CameraImageFragment.java

private Intent createShareIntent() {

    File f = new File(getActivity().getFilesDir(), mCameraName);
    ContentValues values = new ContentValues(2);
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.Images.Media.DATA, f.getAbsolutePath());
    Uri uri = getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.setType("image/jpeg");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mTitle);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, mTitle);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    return shareIntent;
}

From source file:io.nuclei.cyto.share.PackageTargetManager.java

/**
 * WeChat and on some android versions Instagram doesn't seem to handle file providers very well, so instead of those we move the
 * file to external storage and startActivityForResult with the actual file.
 */// w  w  w  .  ja va  2s .  c  o m
protected Intent onExternalStorage(Activity activity, Intent intent, int permissionRequestCode) {
    if (mFile != null) {
        if (ContextCompat.checkSelfPermission(activity,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            File file = ShareUtil.newShareFile(new File(Environment.getExternalStorageDirectory(), ".cyto"),
                    mFile.getName());
            try {
                onCopyFile(mFile, file);
                mFile.delete();
                mFile = file;
            } catch (IOException err) {
                LOG.e("Error copying file for sharing", err);
            }
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mFile));
        } else {
            ActivityCompat.requestPermissions(activity,
                    new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, permissionRequestCode);
            return null;
        }
        if (intent.hasExtra(Intent.EXTRA_STREAM) && intent.hasExtra(Intent.EXTRA_TEXT))
            intent.removeExtra(Intent.EXTRA_TEXT);
    }
    return intent;
}

From source file:com.nicefontaine.seanachie.ui.imagestory.ImageStoryFragment.java

public void sendEmail() {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND).setType("application/image")
            .putExtra(android.content.Intent.EXTRA_SUBJECT, currentStory.getCategoriesContent())
            .putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.story_create_send_with));
    String path = currentStory.getImagePath();
    if (!isNull(path)) {
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    }//from w ww. j ava  2  s.c  om
    startActivity(Intent.createChooser(emailIntent, getString(R.string.story_create_sending)));
}

From source file:com.studyjams.mdvideo.PlayerModule.PlayerActivity.java

private void onShown() {

    Intent intent = getIntent();/*from   w w w .ja v a 2 s.co  m*/
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type.equals("video/*")) {
        contentUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        contentType = Util.TYPE_SS;
        contentId = "";
        provider = "0";
    } else {
        contentUri = intent.getData();
        contentType = intent.getIntExtra(CONTENT_TYPE_EXTRA,
                inferContentType(contentUri, intent.getStringExtra(CONTENT_EXT_EXTRA)));
        contentId = intent.getStringExtra(CONTENT_ID_EXTRA);
        provider = intent.getStringExtra(PROVIDER_EXTRA);
    }

    configureSubtitleView();
    if (player == null) {
        if (!maybeRequestPermission()) {
            preparePlayer(true);
        }
    } else {
        player.setBackgrounded(false);
    }
}