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:de.tap.easy_xkcd.fragments.comics.FavoritesFragment.java

private void exportFavorites() {
    //Export the full favorites list as text
    StringBuilder sb = new StringBuilder();
    String newline = System.getProperty("line.separator");
    for (int i = 0; i < favorites.length; i++) {
        sb.append(favorites[i]).append(" - ");
        sb.append(prefHelper.getTitle(favorites[i]));
        sb.append(newline);/*  www. ja va 2  s  .  com*/
    }
    try {
        File sdCard = prefHelper.getOfflinePath();
        File dir = new File(sdCard.getAbsolutePath() + "/easy xkcd");
        File file = new File(dir, "favorites.txt");
        FileWriter writer = new FileWriter(file);
        writer.append(sb.toString());
        writer.flush();
        writer.close();
        //Provide option to send to any app that accepts text/plain content
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        Uri uri = FileProvider.getUriForFile(getActivity(), "de.tap.easy_xkcd.fileProvider", file);
        sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.pref_export)));
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), "Export failed", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.orpheusdroid.screenrecorder.RecorderService.java

private void showShareNotification() {
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND)
            .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(SAVEPATH))).setType("video/mp4");
    PendingIntent sharePendingIntent = PendingIntent.getActivity(this, 0,
            Intent.createChooser(Shareintent, getString(R.string.share_intent_title)),
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder shareNotification = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.share_intent_notification_title))
            .setContentText(getString(R.string.share_intent_notification_content))
            .setSmallIcon(R.drawable.ic_notification)
            .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setAutoCancel(true)
            .setContentIntent(sharePendingIntent).addAction(android.R.drawable.ic_menu_share,
                    getString(R.string.share_intent_notification_action_text), sharePendingIntent);
    updateNotification(shareNotification.build(), Const.SCREEN_RECORDER_SHARE_NOTIFICATION_ID);
}

From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java

@SuppressLint("NewApi")
@Override//from  ww w  .  j  ava 2  s.c  o  m
public boolean onContextItemSelected(MenuItem item) {
    Log.v(TAG, "onContextItemSelected");

    WebView.HitTestResult result = webView.getHitTestResult();
    Log.d(TAG, "result: " + result.getExtra());
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);

    switch (item.getItemId()) {
    case R.id.itemSaveImage:
    case R.id.itemSaveLink:

        try {
            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            Request request = new Request(Uri.parse(result.getExtra()));
            dm.enqueue(request);
        } catch (Exception e) {
            Toast.makeText(this, "sBrowser - Error saving...", Toast.LENGTH_SHORT).show();
            Log.d(TAG, "Erro Downloading: " + e);
        }
        break;

    case R.id.itemCopyLink:

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(result.getExtra());
        } else {
            android.content.ClipboardManager newClipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("label", result.getExtra());
            newClipboard.setPrimaryClip(clip);
        }

        break;

    case R.id.itemShareLink:

        try {
            sharingIntent.setType("text/html");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, result.getExtra());
            startActivity(Intent.createChooser(sharingIntent, "Share using..."));
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Erro Sharing link: " + e);
        }

        break;

    case R.id.itemShareImage:

        try {
            sharingIntent.setType("image/*");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, result.getExtra());
            startActivity(Intent.createChooser(sharingIntent, "Share image using..."));
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Erro Sharing Image: " + e);
        }

        break;
    }

    return super.onContextItemSelected(item);
}

From source file:com.bullmobi.base.ui.fragments.dialogs.FeedbackDialog.java

private void attachLog(@NonNull Intent intent) {
    Context context = getActivity();

    try {//from ww w  .  jav a  2 s.c  om
        String log = Logcat.capture();
        if (log == null)
            throw new Exception("Failed to capture the logcat.");

        // Prepare cache directory.
        File cacheDir = context.getCacheDir();
        if (cacheDir == null)
            throw new Exception("Cache directory is inaccessible");
        File directory = new File(cacheDir, LogsProviderBase.DIRECTORY);
        FileUtils.deleteRecursive(directory); // Clean-up cache folder
        if (!directory.mkdirs())
            throw new Exception("Failed to create cache directory.");

        // Create log file.
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        String fileName = "EasyNotification_log_" + sdf.format(new Date()) + ".txt";
        File file = new File(directory, fileName);

        // Write to the file.
        if (!FileUtils.writeToFile(file, log))
            throw new Exception("Failed to write log to the file.");

        // Put extra stream to the intent.
        Uri uri = Uri.parse("content://" + LogAttachmentProvider.AUTHORITY + "/" + fileName);
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    } catch (Exception e) {
        String message = ResUtils.getString(getResources(), R.string.feedback_error_accessing_log,
                e.getMessage());
        ToastUtils.showLong(context, message);
    }
}

From source file:com.cypress.cysmart.DataLoggerFragments.DataLoggerFragment.java

/**
 * Sharing the data logger txt file/*w  w  w  . ja  v  a 2  s .co  m*/
 */
private void shareDataLoggerFile() {
    HomePageActivity.containerView.invalidate();
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    // set the type to 'email'
    emailIntent.setType("vnd.android.cursor.dir/email");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, "");
    // the attachment
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(mFilepath)));
    // the mail subject
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Data Logger File");
    startActivity(Intent.createChooser(emailIntent, "Send email..."));

}

From source file:com.jtechme.apphub.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED)
        return;// w ww  .  ja  va2 s  . c o m
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static Intent createSendFileToAlfrescoIntent(Activity activity, File contentFile) {
    Intent i = new Intent(activity, PublicDispatcherActivity.class);
    i.setAction(Intent.ACTION_SEND);/* w  w  w  . ja  v a2s  . co  m*/
    i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(contentFile));
    i.setType(MimeTypeManager.getMIMEType(activity, contentFile.getName()));
    return i;
}

From source file:com.fvd.nimbus.PaintActivity.java

/** Called when the activity is first created. */
@Override//w w w .j  a va2  s. com
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
    overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    try {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    } catch (Exception e) {
        e.printStackTrace();
    }
    ctx = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    dWidth = prefs.getInt("dWidth", 2);
    fWidth = prefs.getInt("fWidth", 1);
    dColor = prefs.getInt(pColor, Color.RED);
    saveFormat = Integer.parseInt(prefs.getString("saveFormat", "1"));
    serverHelper.getInstance().setCallback(this, this);
    serverHelper.getInstance().setMode(saveFormat);
    setContentView(R.layout.screen_edit);
    drawer = (DrawerLayout) findViewById(R.id.root);
    findViewById(R.id.bDraw1).setOnClickListener(this);
    findViewById(R.id.bDraw2).setOnClickListener(this);
    findViewById(R.id.bDraw3).setOnClickListener(this);
    findViewById(R.id.bDraw4).setOnClickListener(this);
    findViewById(R.id.bDraw5).setOnClickListener(this);
    findViewById(R.id.bDraw6).setOnClickListener(this);
    findViewById(R.id.bDraw8).setOnClickListener(this);
    findViewById(R.id.bColor1).setOnClickListener(this);
    findViewById(R.id.bColor2).setOnClickListener(this);
    findViewById(R.id.bColor3).setOnClickListener(this);
    findViewById(R.id.bColor4).setOnClickListener(this);
    findViewById(R.id.bColor5).setOnClickListener(this);
    paletteButton = (CircleButton) findViewById(R.id.bToolColor);
    paletteButton.setOnClickListener(this);

    paletteButton_land = (CircleButton) findViewById(R.id.bToolColor_land);
    //paletteButton_land.setOnClickListener(this);

    ((SeekBar) findViewById(R.id.seekBarLine)).setProgress(dWidth * 10);
    ((SeekBar) findViewById(R.id.seekBarType)).setProgress(fWidth * 10);

    ((TextView) findViewById(R.id.tvTextType)).setText(String.format("%d", 40 + fWidth * 20));

    findViewById(R.id.bUndo).setOnClickListener(this);
    findViewById(R.id.btnBack).setOnClickListener(this);
    findViewById(R.id.bClearAll).setOnClickListener(this);
    findViewById(R.id.bTurnLeft).setOnClickListener(this);
    findViewById(R.id.bTurnRight).setOnClickListener(this);
    findViewById(R.id.bDone).setOnClickListener(this);
    findViewById(R.id.bApplyText).setOnClickListener(this);

    ((ImageButton) findViewById(R.id.bStroke)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            v.setSelected(!v.isSelected());
        }
    });

    lineWidthListener = new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub
            if (true || fromUser) {
                /*dWidth = (progress/10);
                 drawView.setWidth((dWidth+1)*5);*/
                dWidth = progress;
                drawView.setWidth(dWidth);
                Editor e = prefs.edit();
                e.putInt("dWidth", dWidth);
                e.commit();
            }

        }
    };

    ((SeekBar) findViewById(R.id.seekBarLine)).setOnSeekBarChangeListener(lineWidthListener);
    ((SeekBar) findViewById(R.id.ls_seekBarLine)).setOnSeekBarChangeListener(lineWidthListener);

    fontSizeListener = new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub

            if (fromUser) {
                fWidth = progress / 10;
                int c = 40 + fWidth * 20;
                drawView.setFontSize(c);
                Editor e = prefs.edit();
                e.putInt("fWidth", fWidth);
                e.commit();
                try {
                    ((TextView) findViewById(R.id.tvTextType)).setText(String.format("%d", c));
                    ((TextView) findViewById(R.id.ls_tvTextType)).setText(String.format("%d", c));
                } catch (Exception ex) {

                }

            }
        }
    };

    ((SeekBar) findViewById(R.id.seekBarType)).setOnSeekBarChangeListener(fontSizeListener);
    ((SeekBar) findViewById(R.id.ls_seekBarType)).setOnSeekBarChangeListener(fontSizeListener);

    drawView = (DrawView) findViewById(R.id.painter);
    drawView.setWidth((dWidth + 1) * 5);
    drawView.setFontSize(40 + fWidth * 20);

    setBarConfig(getResources().getConfiguration().orientation);

    findViewById(R.id.bEditPage).setOnClickListener(this);
    findViewById(R.id.bToolColor).setOnClickListener(this);
    findViewById(R.id.bErase).setOnClickListener(this);
    findViewById(R.id.bToolShape).setOnClickListener(this);
    findViewById(R.id.bToolText).setOnClickListener(this);
    findViewById(R.id.bToolCrop).setOnClickListener(this);
    findViewById(R.id.btnBack).setOnClickListener(this);
    findViewById(R.id.bDone).setOnClickListener(this);
    findViewById(R.id.btnShare).setOnClickListener(this);
    findViewById(R.id.bSave2SD).setOnClickListener(this);
    findViewById(R.id.bSave2Nimbus).setOnClickListener(this);

    userMail = prefs.getString("userMail", "");
    userPass = prefs.getString("userPass", "");
    sessionId = prefs.getString("sessionId", "");

    appSettings.sessionId = sessionId;
    appSettings.userMail = userMail;
    appSettings.userPass = userPass;

    storePath = "";
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    //storePath= intent.getPackage().getClass().toString();
    if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SEND.equals(action)
            || "com.onebit.nimbusnote.EDIT_PHOTO".equals(action)) && type != null) {
        if (type.startsWith("image/")) {
            Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            if (imageUri == null)
                imageUri = intent.getData();
            if (imageUri != null) {
                String url = Uri.decode(imageUri.toString());
                if (url.startsWith(CONTENT_PHOTOS_URI_PREFIX)) {
                    url = getPhotosPhotoLink(url);
                } //else url=Uri.decode(url);

                ContentResolver cr = getContentResolver();
                InputStream is;

                try {
                    is = cr.openInputStream(Uri.parse(url));
                    if ("com.onebit.nimbusnote.EDIT_PHOTO".equals(action))
                        storePath = " ";//getGalleryPath(Uri.parse(url));
                    Bitmap bmp = BitmapFactory.decodeStream(is);
                    if (bmp.getWidth() != -1 && bmp.getHeight() != -1)
                        drawView.setBitmap(bmp, 0);
                } catch (Exception e) {
                    appSettings.appendLog("paint:onCreate  " + e.getMessage());
                }
            }
        }
    } else {
        String act = getIntent().getExtras().getString("act");
        if ("photo".equals(act)) {
            getPhoto();
        } else if ("picture".equals(act)) {
            getPicture();
        } else {
            String filePath = getIntent().getExtras().getString("path");
            boolean isTemp = getIntent().getExtras().getBoolean("temp");
            domain = getIntent().getExtras().getString("domain");
            if (domain == null)
                domain = serverHelper.getDate();
            if (filePath.contains("://")) {
                Bitmap bmp = helper.LoadImageFromWeb(filePath);
                if (bmp != null) {
                    drawView.setBitmap(bmp, 0);
                }
            } else {
                File file = new File(filePath);
                if (file.exists()) {
                    try {
                        int orient = helper.getOrientationFromExif(filePath);
                        Bitmap bmp = helper.decodeSampledBitmap(filePath, 1000, 1000);
                        if (bmp != null) {
                            drawView.setBitmap(bmp, orient);
                        }
                    } catch (Exception e) {
                        appSettings.appendLog("paint.onCreate()  " + e.getMessage());
                    }
                    if (isTemp)
                        file.delete();
                }
            }
        }
    }

    drawView.setBackgroundColor(Color.WHITE);
    drawView.requestFocus();
    drawView.setColour(dColor);
    setPaletteColor(dColor);

    drawView.setSelChangeListener(new shapeSelectionListener() {

        @Override
        public void onSelectionChanged(int shSize, int fSize, int shColor) {
            setSelectedFoot(0);
            setLandToolSelected(R.id.bEditPage_land);
            //updateColorDialog(shSize!=-1?(shSize/5)-1:dWidth, fSize!=-1?(fSize-40)/20:fWidth, shColor!=0?colorToId(shColor):dColor);
            dColor = shColor;
            ccolor = shColor;
            int sw = shSize != -1 ? shSize : dWidth;
            canChange = false;
            ((SeekBar) findViewById(R.id.seekBarLine)).setProgress(sw);
            ((SeekBar) findViewById(R.id.ls_seekBarLine)).setProgress(sw);
            setPaletteColor(dColor);
            drawView.setColour(dColor);
            canChange = true;
        }

        @Override
        public void onTextChanged(String text, boolean stroke) {

            if (findViewById(R.id.text_field).getVisibility() != View.VISIBLE) {
                hideTools();

                findViewById(R.id.bStroke).setSelected(stroke);
                ((EditText) findViewById(R.id.etEditorText)).setText(text);
                findViewById(R.id.text_field).setVisibility(View.VISIBLE);
                findViewById(R.id.etEditorText).requestFocus();
                ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                        .showSoftInput(findViewById(R.id.etEditorText), 0);
                findViewById(R.id.bToolText).postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        setSelectedFoot(2);

                    }
                }, 100);

            }
        }

    });

    setColorButtons(dColor);

    //mPlanetTitles = getResources().getStringArray(R.array.lmenu_paint);

    /*ListView listView = (ListView) findViewById(R.id.left_drawer);
    listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_paint)));
    listView.setOnItemClickListener(this);*/
}

From source file:com.yi4all.rupics.ImageDetailActivity.java

private Intent createShareIntent() {
    String path = Utils.convertUrl2Path(this, imgList.get(imageSequence).getUrl());
    if (path != null && new File(path).exists()) {
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sendShareMmsSubject));
        sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.sendShareMmsBody));
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        sendIntent.setType("image/*");
        return sendIntent;
    }/*  w w  w.j av a 2 s  . c  o m*/

    return null;
}

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

@Override
public void onShareOptionsPositiveClick(DialogFragment dialog, RenderStyles renderStyle,
        RenderFormats renderFormat, String intentAction) throws Exception {

    Uri uriFile;//w  w w  .jav  a 2s  .co  m
    String type;
    switch (renderFormat) {
    case Bitmap:
        uriFile = saveBitmap(renderStyle);
        type = "image/png";
        break;
    case PDF:
        uriFile = savePDF(renderStyle);
        type = "application/pdf";
        break;
    case QuiltDesign:
        uriFile = saveQuiltDesign();
        type = "application/vnd.richtodd.quiltdesign";
        break;
    default:
        throw new IllegalArgumentException("Unknown render format " + renderFormat);
    }

    Intent intent = new Intent(intentAction);
    if (intentAction.equals(Intent.ACTION_SEND)) {
        intent.putExtra(Intent.EXTRA_STREAM, uriFile);
        intent.setType(type);
        startActivity(Intent.createChooser(intent, "Share With"));
    } else {
        intent.setDataAndType(uriFile, type);
        startActivity(Intent.createChooser(intent, "View With"));
    }
}