Java Code Examples for android.os.Environment.DIRECTORY_PICTURES

The following are Jave code examples for showing how to use DIRECTORY_PICTURES of the android.os.Environment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: WhatsAppStatusSaver   File: StatusSavingService.java   View Source Code Vote up 6 votes
private void saveAllSelectedStatus(ArrayList<String> statuses){
    String fileType = Environment.DIRECTORY_PICTURES;
    for(String status : statuses){
        if(status.endsWith(".jpg")){
            fileType = "Pictures";
        }else if(status.endsWith(".gif")){
            fileType ="Gifs";
        }else if(status.endsWith(".mp4")){
            fileType="Videos";
        }
        String [] splitStatus = status.split("/");
        String destinationFilename = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
                +"/WhatsAppSaver"+File.separatorChar+splitStatus[splitStatus.length-1];
        try {
            copyFile(new File(status),new File(destinationFilename));
            Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
            intent.setData(Uri.fromFile(new File(destinationFilename)));
            sendBroadcast(intent);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Project: WhatsAppStatusSaver   File: FloatingButtonService.java   View Source Code Vote up 6 votes
private void saveAllSelectedStatus(ArrayList<String> statuses){
    String fileType = Environment.DIRECTORY_PICTURES;
    for(String status : statuses){
        if(status.endsWith(".jpg")){
            fileType = "Pictures";
        }else if(status.endsWith(".gif")){
            fileType ="Gifs";
        }else if(status.endsWith(".mp4")){
            fileType="Videos";
        }
        String [] splitStatus = status.split("/");
        String destinationFilename = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
                +"/WhatsAppSaver"+File.separatorChar+splitStatus[splitStatus.length-1];
        try {
            copyFile(new File(status),new File(destinationFilename));
            Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
            intent.setData(Uri.fromFile(new File(destinationFilename)));
            sendBroadcast(intent);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 3
Project: react-native-camera   File: RCTCameraModule.java   View Source Code Vote up 6 votes
private File getOutputMediaFile(int type) {
    // Get environment directory type id from requested media type.
    String environmentDirectoryType;
    if (type == MEDIA_TYPE_IMAGE) {
        environmentDirectoryType = Environment.DIRECTORY_PICTURES;
    } else if (type == MEDIA_TYPE_VIDEO) {
        environmentDirectoryType = Environment.DIRECTORY_MOVIES;
    } else {
        Log.e(TAG, "Unsupported media type:" + type);
        return null;
    }

    return getOutputFile(
            type,
            Environment.getExternalStoragePublicDirectory(environmentDirectoryType)
    );
}
 
Example 4
Project: androidCameraTest   File: PhotoIntentTest.java   View Source Code Vote up 6 votes
private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = (isVideo ? "MPEG_" : "JPEG_") + timeStamp + "_";
    String dirType = isVideo ? Environment.DIRECTORY_MOVIES : Environment.DIRECTORY_PICTURES;
    File storageDir = isPublic ? getExternalStoragePublicDirectory(dirType) :
                                 getExternalFilesDir(dirType);
    if( !storageDir.exists() ) {
        storageDir.mkdirs();
    }
    File image = File.createTempFile(
            imageFileName,
            isVideo ? ".mp4" : ".jpg",
            storageDir
    );

    return image;
}
 
Example 5
Project: react-native-camera-face-detector   File: RCTCameraModule.java   View Source Code Vote up 6 votes
private File getOutputMediaFile(int type) {
    // Get environment directory type id from requested media type.
    String environmentDirectoryType;
    if (type == MEDIA_TYPE_IMAGE) {
        environmentDirectoryType = Environment.DIRECTORY_PICTURES;
    } else if (type == MEDIA_TYPE_VIDEO) {
        environmentDirectoryType = Environment.DIRECTORY_MOVIES;
    } else {
        Log.e(TAG, "Unsupported media type:" + type);
        return null;
    }

    return getOutputFile(
            type,
            Environment.getExternalStoragePublicDirectory(environmentDirectoryType)
    );
}
 
Example 6
Project: react-native-webrtc   File: WebRTCModule.java   View Source Code Vote up 5 votes
private File getOutputMediaFile(String fileName) {
    // Get environment directory type id from requested media type.
    String environmentDirectoryType;
    environmentDirectoryType = Environment.DIRECTORY_PICTURES;

    return getOutputFile(
            fileName + ".jpeg",
            Environment.getExternalStoragePublicDirectory(environmentDirectoryType)
    );
}
 
Example 7
Project: foco   File: EditDocCoverDialog.java   View Source Code Vote up 5 votes
/**
 * Open a file picker dialog to ease select a new image from external storage.
 */
public void openFilePickerDialog() {
    DialogProperties properties = new DialogProperties();

    properties.selection_mode = DialogConfigs.SINGLE_MODE;
    properties.selection_type = DialogConfigs.FILE_SELECT;
    // initial directory should be pictures directory
    properties.offset = new File("/mnt/sdcard" + File.separator + Environment.DIRECTORY_PICTURES);
    // show accepted image format only
    properties.extensions = new String[]{"jpg","jpeg","png","gif","bmp","webp"};

    FilePickerDialog dialog = new FilePickerDialog(getActivity(), properties);
    dialog.setTitle(R.string.dialog_edit_doc_cover_image_select_title);
    dialog.setPositiveBtnName(getString(R.string.dialog_edit_doc_cover_image_select_ok));
    dialog.setNegativeBtnName(getString(android.R.string.cancel));

    dialog.setDialogSelectionListener(new DialogSelectionListener() {
        @Override
        public void onSelectedFilePaths(String[] files) {
            if (files.length > 0) {
                mImagePath = files[0];
                updateImage();
            }
        }
    });

    dialog.show();

    // There is a problem with library dialog theme, it does not support a light
    // primary color because header text color is always white.
    // With this hack (we had to study library layout) it ensures that header background
    // is ok.
    dialog.findViewById(R.id.header).setBackgroundColor(
            ContextCompat.getColor(getActivity(), R.color.colorAccent));
}
 
Example 8
Project: Viewshot   File: Viewshot.java   View Source Code Vote up 5 votes
private String getDirectoryPath() {
    if (directoryPath == null || directoryPath.isEmpty()) {
        return Environment.DIRECTORY_PICTURES;
    } else {
        return directoryPath;
    }
}
 
Example 9
Project: Cable-Android   File: StorageUtil.java   View Source Code Vote up 4 votes
public static File getImageDir() throws NoExternalStorageException {
  return new File(getSignalStorageDir(), Environment.DIRECTORY_PICTURES);
}