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:om.sstvencoder.MainActivity.java

private boolean handleIntent(Intent intent) {
    if (!isIntentTypeValid(intent.getType()) || !isIntentActionValid(intent.getAction()))
        return false;
    Uri uri = intent.hasExtra(Intent.EXTRA_STREAM) ? (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)
            : intent.getData();//from ww w.  j a  va 2 s.  c  o m
    if (uri != null) {
        try {
            ContentResolver resolver = getContentResolver();
            mCropView.setBitmapStream(resolver.openInputStream(uri));
            mCropView.rotateImage(getOrientation(resolver, uri));
            return true;
        } catch (FileNotFoundException ex) {
            if (ex.getCause() instanceof ErrnoException) {
                if (((ErrnoException) ex.getCause()).errno == OsConstants.EACCES) {
                    requestPermissions();
                    return false;
                }
            }
            String s = getString(R.string.load_img_err_title) + ": \n" + ex.getMessage();
            Toast.makeText(this, s, Toast.LENGTH_LONG).show();
        } catch (Exception ex) {
            String s = Utility.createMessage(ex) + "\n\n" + uri + "\n\n" + intent;
            showErrorMessage(getString(R.string.load_img_err_title), ex.getMessage(), s);
        }
    } else {
        String s = getString(R.string.load_img_err_txt_unsupported);
        showErrorMessage(getString(R.string.load_img_err_title), s, s + "\n\n" + intent);
    }
    return false;
}

From source file:com.krayzk9s.imgurholo.activities.ImgurLinkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    destroyed = false;//from  w w  w  .j  av a2 s. c  o  m
    if (getActionBar() != null)
        getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null
            && intent.getData().toString().startsWith("http://imgur.com/a")) {
        String uri = intent.getData().toString();
        album = uri.split("/")[4];
        Log.d("album", album);
        Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
        fetcher.execute();
    } else if (Intent.ACTION_VIEW.equals(action)
            && intent.getData().toString().startsWith("http://imgur.com/gallery/")) {
        String uri = intent.getData().toString();
        final String album = uri.split("/")[4];
        if (album.length() == 5) {
            Log.d("album", album);
            Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
            fetcher.execute();
        } else if (album.length() == 7) {
            Log.d("image", album);
            Fetcher fetcher = new Fetcher(this, "/3/gallery/image/" + album, ApiCall.GET, null, apiCall, IMAGE);
            fetcher.execute();
        }
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("http://i.imgur")) {
        String uri = intent.getData().toString();
        final String image = uri.split("/")[3].split("\\.")[0];
        Log.d("image", image);
        Fetcher fetcher = new Fetcher(this, "/3/image/" + image, ApiCall.GET, null, apiCall, IMAGE);
        fetcher.execute();
    }
}

From source file:com.trellmor.mocklocationpicture.MLPActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mlpactivity);

    mImagePreview = (ImageView) findViewById(R.id.image_preview);

    Intent intent = getIntent();/*from   ww w.  j a  v a2s  .  c  om*/
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null && type.startsWith("image/")) {
        // Started by share intent, display preview image
        setImageUri((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
        intent.setAction("");
    } else if (savedInstanceState != null) {
        setImageUri((Uri) savedInstanceState.getParcelable(KEY_IMAGE_URI));
    }
}

From source file:com.granita.contacticloudsync.ui.DebugInfoActivity.java

public void onShare(MenuItem item) {
    if (!TextUtils.isEmpty(report)) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Exception Details");

        try {/* ww w  .j av  a2  s . c om*/
            File reportFile = File.createTempFile("debug", ".txt", getExternalCacheDir());
            Constants.log.debug("Writing debug info to " + reportFile.getAbsolutePath());
            FileWriter writer = new FileWriter(reportFile);
            writer.write(report);
            writer.close();

            sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(reportFile));
        } catch (IOException e) {
            // let's hope the report is < 1 MB
            sendIntent.putExtra(Intent.EXTRA_TEXT, report);
        }

        startActivity(sendIntent);
    }
}

From source file:de.wikilab.android.friendica01.FileUploadService.java

private void showFailMsg(Context ctx, String txt) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt);

    //Instantiate the Notification:
    CharSequence tickerText = "Upload failed, please retry!";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    CharSequence contentTitle = "Upload failed, click to retry!";
    CharSequence contentText = txt;
    Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class);
    Bundle b = new Bundle();
    b.putParcelable(Intent.EXTRA_STREAM, fileToUpload);
    b.putString(Intent.EXTRA_SUBJECT, subject);
    b.putString(EXTRA_DESCTEXT, descText);

    notificationIntent.putExtras(b);//  w  w w  . j  a  v a  2 s .c  o  m
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_FAILED_ID, notification);
    //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show();
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an Intent for sharing/sending a file and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param file the File instance to be shared
 * @param mimeType the MIME type for the file to be shared (e.g. image/jpeg)
 * @param messageTitle the message title/subject that may be provided in addition to the file, if supported by the target app
 *//*from   ww w .  j  a  v  a  2s.  c o m*/
public static void shareFile(Context context, String windowTitle, File file, final String mimeType,
        String messageTitle) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}

From source file:nl.hnogames.domoticz.Fragments.Camera.java

private void processImage() {
    // Get access to the URI for the bitmap
    File file = new File(url);
    Uri bmpUri = Uri.fromFile(file);/*  w  w  w .  j  a v a2 s . co m*/
    if (bmpUri != null) {
        // Construct a ShareIntent with link to image
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.setType("image/*");
        // Launch sharing dialog for image
        startActivity(Intent.createChooser(shareIntent, "Share Image"));
    }
}

From source file:me.egorand.cats.ui.activities.CatViewerActivity.java

private void initShareActionProvider(Menu menu) {
    MenuItem shareMenuItem = menu.findItem(R.id.action_share);
    ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);
    Intent shareIntent = new Intent(Intent.ACTION_VIEW);
    shareIntent.setType(catImage.getType());
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(catImage.getLink()));
    actionProvider.setShareIntent(shareIntent);
    actionProvider.setOnShareTargetSelectedListener((source, intent) -> {
        trackSharingAction(analyticsTrackerHelper, AnalyticsTags.CATEGORY_ACTION, AnalyticsTags.ACTION_SHARE);
        return true;
    });/*from  ww  w  .  j a va  2  s  . c  o m*/
}

From source file:info.schnatterer.logbackandroiddemo.SendLogActivity.java

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

    /* Get URIs for log files using android.support.v4.content.FileProvider */
    ArrayList<Uri> uris = new ArrayList<>();
    for (final File fileEntry : Logs.getLogFiles(this)) {
        // Don't recurse!
        if (!fileEntry.isDirectory()) {
            // Create content provider URI
            uris.add(FileProvider.getUriForFile(this, getString(R.string.authority_log_file_provider),
                    fileEntry));/*from w  ww  .  ja  va2  s .c om*/
        }
    }

    final Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
    email.setType("message/rfc822");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { "a@b.c" });
    email.putExtra(Intent.EXTRA_SUBJECT, getString(getApplicationInfo().labelRes));
    email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    email.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(email);

    finish();
}

From source file:com.nuvolect.securesuite.data.ExportVcf.java

public static void emailVcf(Activity act, long contact_id) {

    String messageTitle = "vCard for ";
    String messageBody = "\n\n\nContact from SecureSuite, a secure contact manager";

    try {//  www  .j  av  a2  s  .  c om
        String displayName = SqlCipher.get(contact_id, ATab.display_name);
        String fileName = displayName.replaceAll("\\W+", "");
        if (fileName.isEmpty())
            fileName = "contact";
        fileName = fileName + ".vcf";

        new File(act.getFilesDir() + CConst.SHARE_FOLDER).mkdirs();
        File vcf_file = new File(act.getFilesDir() + CConst.SHARE_FOLDER + fileName);

        writeContactVcard(contact_id, vcf_file);

        // Must match "authorities" in Manifest provider definition
        String authorities = act.getResources().getString(R.string.app_authorities) + ".provider";

        Uri uri = null;
        try {
            uri = FileProvider.getUriForFile(act, authorities, vcf_file);
        } catch (IllegalArgumentException e) {
            LogUtil.logException(act, LogType.EXPORT_VCF, e);
        }

        //convert from paths to Android friendly Parcelable Uri's
        ArrayList<Uri> uris = new ArrayList<Uri>();
        uris.add(uri);

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle + displayName);
        intent.putExtra(Intent.EXTRA_TEXT, messageBody);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("path", vcf_file.getAbsolutePath());

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        act.startActivityForResult(Intent.createChooser(intent, "Share with..."),
                CConst.RESPONSE_CODE_SHARE_VCF);

    } catch (Exception e) {
        LogUtil.logException(act, LogType.EXPORT_VCF, e);
    }
}