Example usage for android.os Environment DIRECTORY_RINGTONES

List of usage examples for android.os Environment DIRECTORY_RINGTONES

Introduction

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

Prototype

String DIRECTORY_RINGTONES

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

Click Source Link

Document

Standard directory in which to place any audio files that should be in the list of ringtones that the user can select (not as regular music).

Usage

From source file:Main.java

public static String getSaveImgPath(Context context, String url) {
    //      String fileName = url.substring(url.lastIndexOf("/") + 1);
    File mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES), SaveImg);

    return mediaStorageDir.getPath();
    //            + File.separator + fileName;
}

From source file:Main.java

public static String getDownAudioPath(Context context, String url) {
    String fileName = url.substring(url.lastIndexOf("/") + 1);
    File mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES),
            AudioFolderName);/*  w ww  . j av  a  2  s. com*/

    return mediaStorageDir.getPath() + File.separator + fileName;
}

From source file:Main.java

public static String getOutputAudioPath(Context context, String mediaName) {
    File mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES),
            AudioFolderName);//from  w w w  .ja  va2 s.c  o m

    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }

    File noMediaFile = new File(mediaStorageDir, ".nomedia");
    if (!noMediaFile.exists()) {
        try {
            noMediaFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return mediaStorageDir.getPath() + File.separator + mediaName;
}

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:// w w  w. j  a  va2s .  co m
        throw new IllegalArgumentException("Invalid directory representation: " + name);
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private boolean copyPart(PduPart part, String fallback) {
    Uri uri = part.getDataUri();//from  w w  w.ja  v  a 2 s  .  com
    String type = new String(part.getContentType());
    boolean isDrm = DrmUtils.isDrmType(type);
    if (isDrm) {
        type = MmsApp.getApplication().getDrmManagerClient().getOriginalMimeType(part.getDataUri());
    }
    if (!ContentType.isImageType(type) && !ContentType.isVideoType(type) && !ContentType.isAudioType(type)) {
        return true; // we only save pictures, videos, and sounds. Skip the text parts,
                     // the app (smil) parts, and other type that we can't handle.
                     // Return true to pretend that we successfully saved the part so
                     // the whole save process will be counted a success.
    }
    InputStream input = null;
    FileOutputStream fout = null;
    try {
        input = mContentResolver.openInputStream(uri);
        if (input instanceof FileInputStream) {
            FileInputStream fin = (FileInputStream) input;

            byte[] location = part.getName();
            if (location == null) {
                location = part.getFilename();
            }
            if (location == null) {
                location = part.getContentLocation();
            }

            String fileName;
            if (location == null) {
                // Use fallback name.
                fileName = fallback;
            } else {
                // For locally captured videos, fileName can end up being something like this:
                //      /mnt/sdcard/Android/data/com.android.mms/cache/.temp1.3gp
                fileName = new String(location);
            }
            File originalFile = new File(fileName);
            fileName = originalFile.getName(); // Strip the full path of where the "part" is
                                               // stored down to just the leaf filename.

            // Depending on the location, there may be an
            // extension already on the name or not. If we've got audio, put the attachment
            // in the Ringtones directory.
            String dir = Environment.getExternalStorageDirectory() + "/"
                    + (ContentType.isAudioType(type) ? Environment.DIRECTORY_RINGTONES
                            : Environment.DIRECTORY_DOWNLOADS)
                    + "/";
            String extension;
            int index;
            if ((index = fileName.lastIndexOf('.')) == -1) {
                extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(type);
            } else {
                extension = fileName.substring(index + 1, fileName.length());
                fileName = fileName.substring(0, index);
            }
            if (isDrm) {
                extension += DrmUtils.getConvertExtension(type);
            }
            // Remove leading periods. The gallery ignores files starting with a period.
            fileName = fileName.replaceAll("^.", "");

            File file = getUniqueDestination(dir + fileName, extension);

            // make sure the path is valid and directories created for this file.
            File parentFile = file.getParentFile();
            if (!parentFile.exists() && !parentFile.mkdirs()) {
                Log.e(TAG, "[MMS] copyPart: mkdirs for " + parentFile.getPath() + " failed!");
                return false;
            }

            fout = new FileOutputStream(file);

            byte[] buffer = new byte[8000];
            int size = 0;
            while ((size = fin.read(buffer)) != -1) {
                fout.write(buffer, 0, size);
            }

            // Notify other applications listening to scanner events
            // that a media file has been added to the sd card
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
        }
    } catch (IOException e) {
        // Ignore
        Log.e(TAG, "IOException caught while opening or reading stream", e);
        return false;
    } finally {
        if (null != input) {
            try {
                input.close();
            } catch (IOException e) {
                // Ignore
                Log.e(TAG, "IOException caught while closing stream", e);
                return false;
            }
        }
        if (null != fout) {
            try {
                fout.close();
            } catch (IOException e) {
                // Ignore
                Log.e(TAG, "IOException caught while closing stream", e);
                return false;
            }
        }
    }
    return true;
}