Example usage for android.os Environment DIRECTORY_DOCUMENTS

List of usage examples for android.os Environment DIRECTORY_DOCUMENTS

Introduction

In this page you can find the example usage for android.os Environment DIRECTORY_DOCUMENTS.

Prototype

String DIRECTORY_DOCUMENTS

To view the source code for android.os Environment DIRECTORY_DOCUMENTS.

Click Source Link

Document

Standard directory in which to place documents that have been created by the user.

Usage

From source file:Main.java

public static File getAppStorageDir(Context context) {
    File file = context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
    if (!file.mkdirs()) {
    }/*from  ww  w. ja va  2s .c  o  m*/
    return file;
}

From source file:io.v.android.apps.reader.Utils.java

/**
 * Returns an app-independent files directory for saving log files, to avoid accidentally
 * deleting log files by clearing the app data.
 */// w ww. j a v  a  2s. com
public static File getLogDirectory() {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    return dir;
}

From source file:com.commonsware.android.fileseditor.SampleAdapter.java

@Override
public Fragment getItem(int position) {
    File fileToEdit;/*from  www  . j a va2  s  .c  o m*/

    switch (position) {
    case TAB_INTERNAL:
        fileToEdit = new File(ctxt.getFilesDir(), FILENAME);
        break;

    case TAB_EXTERNAL:
        fileToEdit = new File(ctxt.getExternalFilesDir(null), FILENAME);
        break;

    default:
        fileToEdit = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
                FILENAME);
        break;
    }

    return (EditorFragment.newInstance(fileToEdit));
}

From source file:org.benetech.secureapp.activities.BulletinToMbaFileExporter.java

@Override
public void onZipped(Bulletin bulletin, AsyncTaskResult<File> zippedTaskResult) {
    if (zippedTaskResult.getException() != null) {
        indeterminateDialog.dismissAllowingStateLoss();
        setResult(Activity.RESULT_CANCELED);

        return;//from w  w  w .j  a v a2s.c o  m
    }

    try {
        final File externalStoragePublicDirectory = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
        final String fileName = getApplicationName() + "_" + bulletin.toFileName() + MBA_FILE_EXTENSION;
        final File destinationFile = new File(externalStoragePublicDirectory, fileName);
        FileUtils.copyFile(zippedTaskResult.getResult(), destinationFile);

        ZipFile zipFile = new ZipFile(zippedTaskResult.getResult());
        BulletinZipUtilities.validateIntegrityOfZipFilePackets(store.getAccountId(), zipFile, getSecurity());
    } catch (Exception e) {
        Log.e(TAG, getString(R.string.error_message_error_verifying_zip_file), e);
        indeterminateDialog.dismissAllowingStateLoss();
        Toast.makeText(this, getString(R.string.failure_zipping_bulletin), Toast.LENGTH_SHORT).show();
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    indeterminateDialog.dismissAllowingStateLoss();
    if (zippedTaskResult.getResult() == null) {
        setResult(Activity.RESULT_CANCELED);
        Toast.makeText(this, getString(R.string.failure_zipping_bulletin), Toast.LENGTH_SHORT).show();
        return;
    }

    setResult(Activity.RESULT_OK);
    finish();
}

From source file:com.ultramegasoft.flavordex2.dialog.ExportDialog.java

/**
 * Get the path to the directory where we will save the file.
 *
 * @return The path to the directory where we will save the file
 *///from  ww w.j  av  a  2  s  . c  o m
@NonNull
private static String getBasePath() {
    final File file;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
    } else {
        file = Environment.getExternalStorageDirectory();
    }
    //noinspection ResultOfMethodCallIgnored
    file.mkdirs();
    return file.getPath();
}

From source file:com.nordicsemi.nrfUARTspoon.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);// w  w  w . ja v  a2  s.  c o  m
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    btnStartNewFile = (Button) findViewById(R.id.btn_start_new_file);
    edtMessage = (EditText) findViewById(R.id.sendText);
    fileMessage = (TextView) findViewById(R.id.fileStatusText);
    formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS");
    buttonGo = (Button) findViewById(R.id.btnGO);

    service_init();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    // state of spoon buttons
    stateButtons = new Button[6];
    stateButtons[0] = (Button) this.findViewById(R.id.state0_button);
    stateButtons[1] = (Button) this.findViewById(R.id.state1_button);
    stateButtons[2] = (Button) this.findViewById(R.id.state2_button);
    stateButtons[3] = (Button) this.findViewById(R.id.state3_button);
    stateButtons[4] = (Button) this.findViewById(R.id.state4_button);
    stateButtons[5] = (Button) this.findViewById(R.id.state5_button);
    stateButtons[5].setEnabled(false);
    buttonState = 5;

    final CheckBox expert = (CheckBox) findViewById(R.id.ckBoxExpertMode);
    final ListView listViewData = (ListView) findViewById(R.id.listMessage);

    buttonGo.setVisibility(View.INVISIBLE);
    listViewData.setVisibility(ListView.INVISIBLE);

    //Expert Mode Option
    findViewById(R.id.ckBoxExpertMode).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (expert.isChecked()) {
                listViewData.setVisibility(ListView.VISIBLE);
            } else {
                listViewData.setVisibility(ListView.INVISIBLE);
            }
        }

    });
    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //initialize stable sample
            buttonGo.setVisibility(View.INVISIBLE);
            MainActivity.stable_counter = 0;

            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    if (mDevice != null) {
                        mService.disconnect();

                    }
                }
            }
        }
    });
    // Handler Send button  
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    // Handler File button  
    btnStartNewFile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Close an open file
            if (isFileOpen) {
                btnStartNewFile.setText("Start new file");
                fileMessage.setText("File closed");
                try {
                    Log.i(TAG, "Closing old file");
                    isFileOpen = false;
                    theWriter.flush();
                    theWriter.close();
                    theWriter = null;
                } catch (IOException ioe) {
                    Log.e(TAG, "Could not close previous file");
                }
            } else {
                // Open a new file               
                btnStartNewFile.setText("End file");

                String currentDateTimeStringFile = formatter.format(new Date());
                currentDateTimeStringFile += ".txt";
                File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
                path.mkdirs();
                File theFile = new File(path, currentDateTimeStringFile);
                try {
                    theWriter = new BufferedWriter(new FileWriter(theFile));
                } catch (IOException ioe) {
                    Log.e(TAG, "Buffered writer not created at" + theFile.getPath());
                    return;

                }
                fileMessage.setText("Writing to " + theFile.getPath());
                isFileOpen = true;
                fileTime = 0;
            }
        }
    });

    // Set initial UI state

}

From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java

private String getDirectoryName(String name) {
    switch (name) {
    case "ALARMS":
        return Environment.DIRECTORY_ALARMS;
    case "DCIM":
        return Environment.DIRECTORY_DCIM;
    case "DOCUMENTS":
        return Environment.DIRECTORY_DOCUMENTS;
    case "DOWNLOADS":
        return Environment.DIRECTORY_DOWNLOADS;
    case "MOVIES":
        return Environment.DIRECTORY_MOVIES;
    case "MUSIC":
        return Environment.DIRECTORY_MUSIC;
    case "NOTIFICATIONS":
        return Environment.DIRECTORY_NOTIFICATIONS;
    case "PICTURES":
        return Environment.DIRECTORY_PICTURES;
    case "PODCASTS":
        return Environment.DIRECTORY_PODCASTS;
    case "RINGTONES":
        return Environment.DIRECTORY_RINGTONES;
    default://from   w  w w .ja  v a  2  s . c o  m
        throw new IllegalArgumentException("Invalid directory representation: " + name);
    }
}

From source file:com.att.arocollector.AROCollectorActivity.java

@TargetApi(21)
@Override//w ww  .ja  va 2  s  .com
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    Log.i(TAG, "onActivityResult(... requestCode{" + requestCode + "} resultCode{" + resultCode + "} ...)");

    switch (requestCode) {

    case Config.Permission.VPN_PERMISSION_REQUEST_CODE:
        if (resultCode == RESULT_OK) {

            captureVpnServiceIntent = new Intent(getApplicationContext(), CaptureVpnService.class);
            captureVpnServiceIntent.putExtra("TRACE_DIR", Config.TRACE_DIR);
            captureVpnServiceIntent.putExtra(BundleKeyUtil.PRINT_LOG, printLog);

            if (isExternalStorageWritable()) {
                Log.i(TAG, "TRACE_DIR: " + Config.TRACE_DIR + "trace directory: "
                        + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));

            }

            startService(captureVpnServiceIntent);

            // start collecting META data
            startServices();

            if (doVideoCapture()) {
                getVideoCapturePermission();
            }

        } else if (resultCode == RESULT_CANCELED) {
            showVPNRefusedDialog();
        }

        break;

    case Config.Permission.VIDEO_PERMISSION_REQUEST_CODE:
        Log.i("SecureCollector", "VIDEO_PERMISSION_REQUEST_CODE");
        pushAppToBackStack();

        if (resultCode != RESULT_OK) {
            Toast.makeText(this, "Screen Cast Permission Denied, no SD/HD video will be captured.",
                    Toast.LENGTH_SHORT).show();
            return;
        }

        MediaProjection mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data);
        videoCapture = new VideoCapture(getApplicationContext(), getWindowManager(), mediaProjection, bitRate,
                screenSize, videoOrient);
        videoCapture.start();
        break;

    default:
        break;
    }
}

From source file:io.github.silencio_app.silencio.MainActivity.java

public File getAlbumStorageDir(String albumName) {
    // Get the directory for the user's public pictures directory.
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
            albumName);//from www.  j  a v a 2 s.co  m
    if (!file.mkdirs()) {
        file.mkdirs();
    }
    return file;
}