Example usage for android.net Uri fromFile

List of usage examples for android.net Uri fromFile

Introduction

In this page you can find the example usage for android.net Uri fromFile.

Prototype

public static Uri fromFile(File file) 

Source Link

Document

Creates a Uri from a file.

Usage

From source file:com.bloc.blocparty.TimelineFragment.java

public void startCamera() {

    // give the image a name so we can store it in the phone's default
    // location//from ww w  .ja v a2 s .  c o m
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, "IMG_" + timeStamp + ".jpg");

    File f = getOutputMediaFile(MEDIA_TYPE_IMAGE);
    fileUri = Uri.fromFile(f);

    mCurrentPhotoPath = f.getAbsolutePath();
    Log.d("photo path is ", mCurrentPhotoPath.toString());
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra("return-data", true);

    getActivity().setResult(RESULT_OK, intent);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
    // start the image capture Intent
    startActivityForResult(intent, CAMERA_TAKE_PHOTO_REQUEST_CODE);
}

From source file:com.zhihuigu.sosoOffice.RegisterThirdActivity.java

@Override
public void onClick(View v) {
    if (v == backBtn) {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);/*  w ww  .  ja v  a 2s  . c om*/
        finish();
    } else if (v == submitBtn) {
        if (textValidate()) {
            new Thread(runnable).start();
        }
    } else if (v == linearGetImage) {
        int height = MyApplication.getInstance(this).getScreenHeight();
        if (photo_tag) {
            shareBtn3.setVisibility(View.VISIBLE);
            if (height == 1280) {
                chazhi = 670;
            } else if (height == 800) {
                chazhi = 340;
            } else if (height == 960) {
                chazhi = 500;
            } else if (height == 854) {
                chazhi = 400;
            } else if (height == 480) {
                chazhi = 175;
            }
        } else {
            shareBtn3.setVisibility(View.GONE);
            if (height == 1280) {
                chazhi = 800;
            } else if (height == 800) {
                chazhi = 440;
            } else if (height == 960) {
                chazhi = 600;
            } else if (height == 854) {
                chazhi = 492;
            } else if (height == 480) {
                chazhi = 240;
            }
        }
        CommonUtils.hideSoftKeyboard(this);//
        new Thread(runnableForShowDialog).start();

    } else if (v == shareBtn1) {
        dismiss();
        Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        fileName = CommonUtils.getFileName();
        MyApplication.getInstance(this).setFileName(fileName);
        File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD);
        if (!file.exists()) {
            file.mkdirs();
        }
        if (CommonUtils.isHasSdcard()) {
            openCamera.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName)));
        }
        startActivityForResult(openCamera, REQUEST_CODE_TAKE_PICTURE);
    } else if (v == shareBtn2) {
        dismiss();
        Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
        getAlbum.setType(IMAGE_TYPE);
        startActivityForResult(getAlbum, IMAGE_CODE);
    } else if (v == shareBtn3) {
        dismiss();
        //         Intent intent = new Intent(this,ImagePreViewActivity.class);
        //         intent.putExtra("path", path);
        //         startActivityForResult(intent, 6);
        ArrayList<String> al = new ArrayList<String>();
        al.clear();
        al.add(path);
        Intent it = new Intent(this, ImageSwitcher.class);
        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        it.putStringArrayListExtra("pathes", al);
        it.putExtra("index", 0);
        startActivity(it);
    } else if (v == cancleBtn) {
        dismiss();
    }
    super.onClick(v);
}

From source file:com.polyvi.xface.extension.camera.XCameraExt.java

/**
 * ????????//from   w  ww  .  j  a v  a2 s  . c  o  m
 * ???URI???URI??
 *
 * @return ??URI
 */
private Uri createEmptyFileForCroppedImageBeforeCrop() {
    String cropped_image_name = null;
    if (mEncodingType == JPEG) {
        String tempStr = System.currentTimeMillis() + ".jpg";
        cropped_image_name = tempStr + "_cropped.jpg";
    } else if (mEncodingType == PNG) {
        String tempStr = System.currentTimeMillis() + ".png";
        cropped_image_name = tempStr + "_cropped.png";
    } else {
        throw new IllegalArgumentException("Invalid Encoding Type: " + mEncodingType);
    }

    File cropped_image = new File(mWebContext.getWorkSpace(), cropped_image_name);
    mCroppedImageUri = null;
    if (cropped_image.exists()) {
        cropped_image.delete();
    }
    try {
        cropped_image.createNewFile();
        mCroppedImageUri = Uri.fromFile(cropped_image);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return mCroppedImageUri;
}

From source file:cn.ttyhuo.view.UserView.java

/**
 * //from   ww w  . j  a  va  2 s . com
 * @param context 
 * @param activityTitle Activity??
 * @param msgTitle ?
 * @param msgText ?
 * @param imgPath ?null
 */
public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText, File f) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    if (f == null || !f.exists() || !f.isFile()) {
        intent.setType("text/plain"); // 
    } else {
        intent.setType("image/png");
        Uri u = Uri.fromFile(f);
        //Uri u = Uri.parse(imgPath);
        intent.putExtra(Intent.EXTRA_STREAM, u);
    }
    intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
    intent.putExtra(Intent.EXTRA_TEXT, msgText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(Intent.createChooser(intent, activityTitle));
}

From source file:com.github.gorbin.asne.instagram.InstagramSocialNetwork.java

/**
 * Post photo to social network/*from   w ww  . java 2 s. c  o m*/
 * @param photo photo that should be shared
 * @param message message that should be shared with photo
 * @param onPostingCompleteListener listener for posting request
 */
@Override
public void requestPostPhoto(File photo, String message, OnPostingCompleteListener onPostingCompleteListener) {
    super.requestPostPhoto(photo, message, onPostingCompleteListener);
    String instagramPackage = "com.instagram.android";
    String errorMessage = "You should install Instagram app first";
    if (isPackageInstalled(instagramPackage, mSocialNetworkManager.getActivity())) {
        Intent normalIntent = new Intent(Intent.ACTION_SEND);
        normalIntent.setType("image/*");
        normalIntent.setPackage(instagramPackage);
        File media = new File(photo.getAbsolutePath());
        Uri uri = Uri.fromFile(media);
        normalIntent.putExtra(Intent.EXTRA_STREAM, uri);
        normalIntent.putExtra(Intent.EXTRA_TEXT, message);
        mSocialNetworkManager.getActivity().startActivity(normalIntent);
    } else {
        mLocalListeners.get(REQUEST_POST_PHOTO).onError(getID(), REQUEST_POST_PHOTO, errorMessage, null);
    }
    mLocalListeners.remove(REQUEST_POST_PHOTO);
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

/**
 * @param mContext//  w  w  w.j  a  va  2 s .  co  m
 * @param uri
 * @return
 */
public static Attachment createAttachmentFromUri(Context mContext, Uri uri, boolean moveSource) {
    String name = FileHelper.getNameFromUri(mContext, uri);
    String extension = FileHelper.getFileExtension(FileHelper.getNameFromUri(mContext, uri))
            .toLowerCase(Locale.getDefault());
    File f = null;
    if (moveSource) {
        f = createNewAttachmentFile(mContext, extension);
        try {
            FileUtils.moveFile(new File(uri.getPath()), f);
        } catch (IOException e) {
            Log.e(Constants.TAG, "Can't move file " + uri.getPath());
        }
    } else {
        f = StorageManager.createExternalStoragePrivateFile(mContext, uri, extension);
    }
    Attachment mAttachment = null;
    if (f != null) {
        mAttachment = new Attachment(Uri.fromFile(f), StorageManager.getMimeTypeInternal(mContext, uri));
        mAttachment.setName(name);
        mAttachment.setSize(f.length());
    }
    return mAttachment;
}

From source file:com.grass.caishi.cc.activity.RegisterActivity.java

/**
 * onActivityResult/*  w  w  w  . j  a  va 2 s.com*/
 */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ?
        if (cameraFile != null && cameraFile.exists()) {
            // Log.d("cameraFile"+cameraFile.getAbsolutePath());
            // ?uri imageUri = Uri.fromFile(cameraFile);
            cropImageUri(Uri.fromFile(cameraFile), 300, 300, USERPIC_REQUEST_CODE_CUT);

        }
    } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ?
        if (data != null) {
            Uri selectedImage = data.getData();
            if (selectedImage != null) {
                cropImageUri(selectedImage, 300, 300, USERPIC_REQUEST_CODE_CUT);
                // Log.d("log","selectedImage"+selectedImage);

            }
        }
    } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {// ?
        // ?
        if (data != null) {
            Bitmap bitmap = data.getParcelableExtra("data");
            if (bitmap == null) {
                Toast.makeText(RegisterActivity.this, "??", Toast.LENGTH_SHORT).show();
            } else {
                user_logo.setBackgroundColor(Color.parseColor("#00000000"));
                user_logo.setImageBitmap(bitmap);
                lastFile = saveJPGE_After(bitmap, cameraFile); // ????
            }
        } else {
            // Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " + data);
        }
    }
}

From source file:es.uma.lcc.tasks.EncryptionUploaderTask.java

private void showGooglePlusShareButton(String path) {
    Button shareButton = (Button) mMainActivity.findViewById(R.id.shareButton);
    shareButton.setVisibility(View.VISIBLE);
    final String file = path;
    shareButton.setOnClickListener(new OnClickListener() {
        @Override//w w w .j ava2 s . c  o  m
        public void onClick(View v) {
            File f = new File(file);
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/jpeg");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
            intent.setPackage("com.google.android.apps.plus");
            try {
                mMainActivity.startActivity(intent);
            } catch (ActivityNotFoundException anfex) {
                intent.setPackage(null);
                mMainActivity.startActivity(intent);
            }
        }
    });
}

From source file:com.polyvi.xface.extension.zip.XZipExt.java

/**
 * ??zip?/*from   w w w  .  j  a  va2  s . c o  m*/
 *
 * @param dstFileUri
 *            
 * @param is
 *            ?zip?
 * @return ??
 * @throws IOException
 * @throws FileNotFoundException
 * @throws IllegalArgumentException
 */
private void unzipFileFromStream(Uri dstFileUri, InputStream is)
        throws IOException, FileNotFoundException, IllegalArgumentException {
    if (null == dstFileUri || null == is) {
        XLog.e(CLASS_NAME, "Method unzipFileFromStream: params is null");
        throw new IllegalArgumentException();
    }
    ZipInputStream zis = new ZipInputStream(is);
    ZipEntry entry = null;
    Uri unZipUri = null;
    while (null != (entry = zis.getNextEntry())) {
        File unZipFile = new File(dstFileUri.getPath() + File.separator + entry.getName());
        unZipUri = Uri.fromFile(unZipFile);
        if (entry.isDirectory()) {
            if (!unZipFile.exists()) {
                unZipFile.mkdirs();
            }
        } else {
            // ???
            prepareForZipDir(unZipUri);
            OutputStream fos = mResourceApi.openOutputStream(unZipUri);
            int readLen = 0;
            byte buffer[] = new byte[XConstant.BUFFER_LEN];
            while (-1 != (readLen = zis.read(buffer))) {
                fos.write(buffer, 0, readLen);
            }
            fos.close();
        }
    }
    zis.close();
    is.close();
}

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

private Uri savePDF(RenderStyles renderStyle) throws IOException {

    BlockEditFragment fragment = getBlockEditFragment();
    PaperPiecedBlock block = fragment.getBlock();

    File file = new File(StorageUtility.getPublicFolder(), getCurrentBlockName() + ".pdf");

    savePDF(block, file, renderStyle, getCurrentBlockName());

    Uri uri = Uri.fromFile(file);

    return uri;/* w ww . j  av  a2  s  . com*/
}