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.tweetlanes.android.view.HomeActivity.java

void onCreateHandleIntents() {

    boolean turnSoftKeyboardOff = true;

    Intent intent = getIntent();/*from   ww w. ja  v  a  2 s .  c om*/
    if (intent.getAction() == Intent.ACTION_SEND) {

        Bundle extras = intent.getExtras();
        String type = intent.getType();
        if (type.equals("text/plain") == true) {

            String shareString = extras.getString(Intent.EXTRA_TEXT);
            if (extras.containsKey(Intent.EXTRA_TEXT)) {
                shareString = extras.getString(Intent.EXTRA_SUBJECT) + " " + shareString;
            }
            beginShareStatus(shareString);

            turnSoftKeyboardOff = false;
        } else if (type.contains("image/")) {
            // From http://stackoverflow.com/a/2641363/328679
            if (extras.containsKey(Intent.EXTRA_STREAM)) {
                Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
                String scheme = uri.getScheme();
                if (scheme.equals("content")) {
                    ContentResolver contentResolver = getContentResolver();
                    Cursor cursor = contentResolver.query(uri, null, null, null, null);
                    cursor.moveToFirst();
                    try {
                        String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DATA));
                        beginShareImage(imagePath);
                    } catch (java.lang.IllegalArgumentException e) {
                        Toast.makeText(this, R.string.picture_attach_error, Toast.LENGTH_SHORT).show();
                    }

                    turnSoftKeyboardOff = false;
                }
            }
        }
    }

    if (turnSoftKeyboardOff == true) {
        // Turn the soft-keyboard off. For some reason it wants to appear on screen by default when coming back from multitasking...
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}

From source file:com.folkcat.run.activity.PhotoViewPagerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case (android.R.id.home):
        finish();/* ww  w.ja  v  a  2  s  .  c om*/
        break;
    case (R.id.share):
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM,
                Uri.fromFile(new File(mPhotoList.get(mPosition).getPhotoPath())));
        shareIntent.setType("image/jpeg");
        startActivity(Intent.createChooser(shareIntent, getString(R.string.photo_view_activity_share)));
        break;

    default:
        break;
    }
    return true;
}

From source file:de.appplant.cordova.plugin.emailcomposer.EmailComposer.java

/**
 * Fgt die Anhnde zur Mail hinzu.// w w  w .  ja va 2  s .  c o  m
 */
private void setAttachments(JSONArray attachments, Intent draft) throws JSONException {
    ArrayList<Uri> attachmentUris = new ArrayList<Uri>();

    for (int i = 0; i < attachments.length(); i++) {
        Uri attachmentUri = getUriForPath(attachments.getString(i));

        attachmentUris.add(attachmentUri);
    }

    draft.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUris);
}

From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java

protected void submitImage(String tags) {
    Intent intent = getIntent();//w w  w. j  a  va2s  . c  o  m
    Bundle extras = intent.getExtras();
    Uri mImageUri = null;
    File mFilename = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (mImageUri != null) {
                Cursor cursor = getContentResolver().query(mImageUri, null, null, null, null);
                if (cursor.moveToFirst()) {
                    mFilename = new File(cursor.getString(cursor.getColumnIndexOrThrow(ImageColumns.DATA)));
                }
                cursor.close();
                if (mFilename != null) {
                    ZeitGeistReichUploaderTask task = new ZeitGeistReichUploaderTask();
                    ZeitGeistObject o = new ZeitGeistObject(mFilename, tags);
                    task.execute(o);
                }
            }
        }
    }
}

From source file:com.dm.material.dashboard.candybar.adapters.IntentAdapter.java

private Intent addIntentExtra(@NonNull Intent intent) {
    intent.setType("message/rfc822");
    if (mRequest.getStream().length() > 0) {
        File zip = new File(mRequest.getStream());
        Uri uri = FileHelper.getUriFromFile(mContext, mContext.getPackageName(), zip);
        if (uri == null)
            uri = Uri.fromFile(zip);//  ww  w. j  a v  a  2  s.c  om
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mContext.getResources().getString(R.string.dev_email) });
    intent.putExtra(Intent.EXTRA_SUBJECT, mRequest.getSubject());
    intent.putExtra(Intent.EXTRA_TEXT, mRequest.getText());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return intent;
}

From source file:com.example.linhdq.test.documents.viewing.grid.DocumentGridActivity.java

private void checkForImageIntent(Intent intent) {

    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (imageUri != null) {
            loadBitmapFromContentUri(imageUri, ImageSource.INTENT);
        } else {/*from  w  w  w .ja  va 2s.  c om*/
            showFileError(PixLoadStatus.IMAGE_COULD_NOT_BE_READ, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
        }

    }
}

From source file:ar.com.lapotoca.resiliencia.gallery.ui.ImageDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.image_menu, menu);
    MenuItem shareItem = menu.findItem(R.id.menu_share);
    shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from ww w  .j  a v a2  s.  c  o m
        public boolean onMenuItemClick(MenuItem item) {
            try {

                ImageHolder img = Images.image[mPager.getCurrentItem()];
                if (img == null) {
                    return false;
                }

                AnalyticsHelper.getInstance().sendImageShareEvent(img.getUrl());

                Uri bmpUri;
                if (img.isLocal()) {
                    bmpUri = Uri.parse("content://" + AssetProvider.CONTENT_URI + "/" + img.getUrl());
                } else {
                    ImageView iv = (ImageView) findViewById(R.id.picImageView);
                    bmpUri = getLocalBitmapUri(iv);
                }
                if (bmpUri != null) {
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                    shareIntent.setType("image/*");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_item)));

                    AnalyticsHelper.getInstance().sendImageShareCompleted();
                    return true;
                } else {

                    AnalyticsHelper.getInstance().sendImageShareCanceled();
                    return false;
                }
            } catch (Exception e) {
                AnalyticsHelper.getInstance().sendImageShareFailed(e.getMessage());
                return false;
            }
        }
    });

    MenuItem downloadItem = menu.findItem(R.id.download_asset);
    downloadItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {

            Context context = ImageDetailActivity.this;

            String appDirectoryName = context.getString(R.string.app_name);
            File imageRoot = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                    appDirectoryName);

            ImageHolder img = Images.image[mPager.getCurrentItem()];
            if (img == null) {
                return false;
            }

            AssetManager assetManager = context.getAssets();
            try {
                InputStream is = assetManager.open(img.getUrl());
                String fileName = img.getUrl().split("/")[1];

                imageRoot.mkdirs();
                File image = new File(imageRoot, fileName);

                byte[] buffer = new byte[BUFFER_LENGHT];
                FileOutputStream fos = new FileOutputStream(image);
                int read = 0;

                while ((read = is.read(buffer, 0, 1024)) >= 0) {
                    fos.write(buffer, 0, read);
                }

                fos.flush();
                fos.close();
                is.close();

                String[] paths = { image.getAbsolutePath() };

                MediaScannerConnection.scanFile(context, paths, null, null);
                NotificationHelper.showNotification(context,
                        context.getString(R.string.download_image_succesfull));
                AnalyticsHelper.getInstance().sendDownloadImage(fileName);

            } catch (Exception e) {
                NotificationHelper.showNotification(context,
                        context.getString(R.string.download_no_permissions));
                AnalyticsHelper.getInstance().sendImageDownloadFailed(e.getMessage());
            }

            return true;
        }
    });

    return true;
}

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

@Override
protected void onHandleIntent(Intent intent) {
    Log.i("Andfrnd/UploadFile", "onHandleIntent exec");

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    //Instantiate the Notification:
    CharSequence tickerText = "Uploading...";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    notification.setLatestEventInfo(context, "Upload in progress...", "You are notified here when it completes",
            nullIntent);//from www  .j  av  a 2s. c o m

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_PROGRESS_ID, notification);
    /*
    final TwLogin login = new TwLogin();
    login.initialize(FileUploadService.this);
    login.doLogin(FileUploadService.this, null, false);
            
    if (!login.isLoginOK()) {
       showFailMsg(FileUploadService.this, "Invalid login data or no network connection");
       return;
    }
    */
    Bundle intentPara = intent.getExtras();
    fileToUpload = (Uri) intentPara.getParcelable(Intent.EXTRA_STREAM);
    descText = intentPara.getString(EXTRA_DESCTEXT);
    subject = intentPara.getString(Intent.EXTRA_SUBJECT);

    if (targetFilename == null || targetFilename.equals(""))
        targetFilename = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt";

    String fileSpec = Max.getRealPathFromURI(FileUploadService.this, fileToUpload);

    String tempFile = Max.IMG_CACHE_DIR + "/imgUploadTemp_" + System.currentTimeMillis() + ".jpg";
    Max.resizeImage(fileSpec, tempFile, 1024, 768);

    try {
        Log.i("Andfrnd/UploadFile", "before uploadFile");
        final TwAjax uploader = new TwAjax(FileUploadService.this, true, true);
        uploader.addPostFile(new TwAjax.PostFile("media", targetFilename, tempFile));
        uploader.addPostData("status", descText);
        uploader.addPostData("title", subject);
        uploader.addPostData("source",
                "<a href='http://friendica-for-android.wiki-lab.net'>Friendica for Android</a>");
        uploader.uploadFile(Max.getServer(this) + "/api/statuses/update", null);
        Log.i("Andfrnd/UploadFile", "after uploadFile");
        Log.i("Andfrnd/UploadFile", "isSuccess() = " + uploader.isSuccess());
        Log.i("Andfrnd/UploadFile", "getError() = " + uploader.getError());

        mNotificationManager.cancel(UPLOAD_PROGRESS_ID);
        if (uploader.isSuccess() && uploader.getError() == null) {
            JSONObject result = null;
            try {
                Log.i("Andfrnd/UploadFile", "JSON RESULT: " + uploader.getHttpCode());
                result = (JSONObject) uploader.getJsonResult();

                String postedText = result.getString("text");
                showSuccessMsg(FileUploadService.this);

            } catch (Exception e) {
                String errMes = e.getMessage() + " | " + uploader.getResult();
                if (result != null)
                    try {
                        errMes = result.getString("error");
                    } catch (JSONException fuuuuJava) {
                    }

                showFailMsg(FileUploadService.this, errMes);

                e.printStackTrace();
            }
        } else if (uploader.getError() != null) {
            showFailMsg(FileUploadService.this, uploader.getError().toString());
        } else {
            showFailMsg(FileUploadService.this, uploader.getResult());
        }

    } finally {
        new File(tempFile).delete();
    }
}

From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java

@OnClick(R.id.share_all)
public void onShareAllClick() {
    final CharSequence[] items = new String[] { getString(R.string.comma_seperated),
            getString(R.string.share_all_list) };
    new MaterialDialog.Builder(this).title(R.string.choose_share_method).items(items)
            .itemsCallbackSingleChoice(0, (dialog, itemView, which, text) -> {
                if (which == 0) {
                    startActivity(Intent.createChooser(
                            TEXT_SHARE_INTENT.putExtra(EXTRA_TEXT, getCSVUrls().toString()),
                            getString(R.string.share_all)));
                } else {
                    final ArrayList<Uri> webSites = new ArrayList<>();
                    for (Website website : websitesAdapter.getWebsites()) {
                        try {
                            webSites.add(Uri.parse(website.preferredUrl()));
                        } catch (Exception ignored) {
                        }/*from   w w w .  ja  v  a  2 s  . co  m*/
                    }
                    final Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, webSites);
                    shareIntent.setType("text/plain");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_all)));
                }
                return false;
            }).show();
}

From source file:com.shafiq.mytwittle.view.HomeActivity.java

void onCreateHandleIntents() {

    boolean turnSoftKeyboardOff = true;

    Intent intent = getIntent();//from   ww w  . j a v  a  2s .c  om
    if (intent.getAction() == Intent.ACTION_SEND) {

        Bundle extras = intent.getExtras();
        String type = intent.getType();
        if (type.equals("text/plain") == true) {

            String shareString = extras.getString(Intent.EXTRA_TEXT);
            if (extras.containsKey(Intent.EXTRA_TEXT)) {
                shareString = extras.getString(Intent.EXTRA_SUBJECT) + " " + shareString;
            }
            beginShareStatus(shareString);

            turnSoftKeyboardOff = false;
        } else if (type.contains("image/")) {
            // From http://stackoverflow.com/a/2641363/328679
            if (extras.containsKey(Intent.EXTRA_STREAM)) {
                Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
                String scheme = uri.getScheme();
                if (scheme.equals("content")) {
                    ContentResolver contentResolver = getContentResolver();
                    Cursor cursor = contentResolver.query(uri, null, null, null, null);
                    cursor.moveToFirst();
                    try {
                        String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.DATA));
                        beginShareImage(imagePath);
                    } catch (java.lang.IllegalArgumentException e) {
                        Toast.makeText(this, R.string.picture_attach_error, Toast.LENGTH_SHORT).show();
                    }

                    turnSoftKeyboardOff = false;
                }
            }
        }
    }

    if (turnSoftKeyboardOff == true) {
        // Turn the soft-keyboard off. For some reason it wants to appear on
        // screen by default when coming back from multitasking...
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}