Example usage for android.os Environment DIRECTORY_PODCASTS

List of usage examples for android.os Environment DIRECTORY_PODCASTS

Introduction

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

Prototype

String DIRECTORY_PODCASTS

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

Click Source Link

Document

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

Usage

From source file:jupiter.broadcasting.live.holo.Catalogue.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Vector<String> fileArray = new Vector<String>();
    final Vector<String> type = new Vector<String>();
    final Vector<String> path = new Vector<String>();

    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.episodelist_fragment);
    getSupportActionBar().setTitle(R.string.cat);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    catList = (ListView) findViewById(R.id.episodelist);
    catList.setOnItemLongClickListener(liListener);

    cadapter = new CatalogueAdapter(getApplicationContext());

    File fileList = new File(
            Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PODCASTS + "/JB");
    File[] filenames = fileList.listFiles();
    if (filenames != null) {
        for (File tmpf : filenames) {
            if (tmpf.toString().contains(".mp3")) {
                path.add(tmpf.toString());
                String curName = tmpf.toString().split("/")[tmpf.toString().split("/").length - 1];
                fileArray.add(curName.split(".mp3")[0]);
                type.add(getString(R.string.audio));
                cadapter.add(curName.split(".mp3")[0], 0);
            } else if (tmpf.toString().contains(".mp4")) {
                path.add(tmpf.toString());
                String curName = tmpf.toString().split("/")[tmpf.toString().split("/").length - 1];
                fileArray.add(curName.split(".mp4")[0]);
                type.add(getString(R.string.video));
                cadapter.add(curName.split(".mp4")[0], 1);
            }//from w  w w . ja v  a 2  s  . c om
        }
    }

    catList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mActionMode == null) {
                Intent p = new Intent(getBaseContext(), JBPlayer.class);

                p.putExtra("title", fileArray.get(position));
                p.putExtra("offline", true);
                p.putExtra("loc", path.get(position));
                int t = type.get(position).equalsIgnoreCase(getString(R.string.audio)) ? 0 : 1;
                p.putExtra("type", t);
                startActivity(p);
            } else {
                cadapter.change(position, true);
            }
        }
    });
    catList.setAdapter(cadapter);
}

From source file:com.keithandthegirl.services.download.DownloadService.java

@TargetApi(8)
@Override/* w  w  w  .  java2s.c o  m*/
protected void onHandleIntent(Intent requestIntent) {
    Log.v(TAG, "onHandleIntent : enter");

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

    mOriginalRequestIntent = requestIntent;

    Resource resourceType = Resource.valueOf(requestIntent.getStringExtra(RESOURCE_TYPE_EXTRA));
    mCallback = requestIntent.getParcelableExtra(SERVICE_CALLBACK);

    Uri data = requestIntent.getData();
    String urlPath = requestIntent.getStringExtra("urlpath");
    String directory = requestIntent.getStringExtra("directory");

    String filename = data.getLastPathSegment();

    File root;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        switch (resourceType) {
        case MP3:
            root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS);

            break;
        case MP4:
            root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

            break;
        case M4V:
            root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

            break;
        case JPG:
            root = getExternalCacheDir();
            filename = requestIntent.getLongExtra("id", -1) + ".jpg";

            break;
        default:
            root = getExternalCacheDir();

            break;
        }
    } else {
        root = Environment.getExternalStorageDirectory();
    }

    File outputDir = new File(root, directory);
    outputDir.mkdirs();

    File output = new File(outputDir, filename);
    if (output.exists()) {
        result = FragmentActivity.RESULT_OK;

        mCallback.send(result, getOriginalIntentBundle());

        Log.v(TAG, "onHandleIntent : exit, image exists");
        return;
    }

    switch (resourceType) {
    case MP3:
        Log.v(TAG, "onHandleIntent : saving mp3");

        savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath,
                output);
        mCallback.send(result, getOriginalIntentBundle());

        break;

    case MP4:
        Log.v(TAG, "onHandleIntent : saving mp4");

        savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath,
                output);
        mCallback.send(result, getOriginalIntentBundle());

        break;

    case M4V:
        Log.v(TAG, "onHandleIntent : saving m4v");

        savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath,
                output);
        mCallback.send(result, getOriginalIntentBundle());

        break;

    case JPG:
        Log.v(TAG, "onHandleIntent : saving jpg");

        saveBitmap(requestIntent.getStringExtra("filename"), urlPath, output);
        mCallback.send(result, getOriginalIntentBundle());

        break;
    default:
        Log.w(TAG, "onHandleIntent : unknown extension '" + resourceType.getExtension() + "'");

        mCallback.send(REQUEST_INVALID, getOriginalIntentBundle());
        break;
    }

    Log.v(TAG, "onHandleIntent : exit");
}

From source file:com.crossconnect.activity.main.ResourceFragment.java

@Override
public void onListItemClick(ListView l, View v, int pos, long id) {

    final int position = pos;

    //Get the corresponding resource
    final OnlineAudioResource resource = mAdapter.getItem(position);

    final ActionItem playAction = new ActionItem();

    playAction.setTitle("Play");
    playAction.setIcon(getResources().getDrawable(R.drawable.kontak));

    final ActionItem downloadAction = new ActionItem();

    downloadAction.setTitle("Download");
    downloadAction.setIcon(getResources().getDrawable(R.drawable.kontak));

    final ActionItem readAction = new ActionItem();

    readAction.setTitle("Read");
    readAction.setIcon(getResources().getDrawable(R.drawable.kontak));

    final QuickActionHorizontal mQuickAction = new QuickActionHorizontal(v);

    final String text = "blah";

    //Check the links are actually there
    if (resource.getAudioURL() != null) {
        downloadAction.setOnClickListener(new OnClickListener() {
            @Override//from ww w  . j  ava2  s. c o  m
            public void onClick(View v) {

                final String RESOURCE_FOLDER = "/CrossConnectAudio/Resources/";
                Toast.makeText(getActivity(), "Downloading Audio File " + text, Toast.LENGTH_SHORT).show();
                Log.d(TAG, "Downloading Audio " + mAdapter.getItem(position).getResourceName() + "from "
                        + mAdapter.getItem(position).getAudioURL());

                Request request = new Request(Uri.parse(resource.getAudioURL()));
                File path = new File(
                        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
                                + RESOURCE_FOLDER);
                path.mkdir();

                String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
                        + RESOURCE_FOLDER + FileUtil.getFileName(mAdapter.getItem(position), bibleText);

                resourceService.insertUpdate(mAdapter.getItem(position), filePath, bibleText);

                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PODCASTS,
                        RESOURCE_FOLDER + FileUtil.getFileName(mAdapter.getItem(position), bibleText));

                ((DownloadManager) getActivity().getSystemService("download")).enqueue(request);

                mQuickAction.dismiss();
            }
        });
        mQuickAction.addActionItem(downloadAction);

        playAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Streaming Audio File " + text, Toast.LENGTH_SHORT).show();
                Log.d(TAG, "Streaming Audio" + mAdapter.getItem(position).getResourceName() + "from "
                        + mAdapter.getItem(position).getAudioURL());
                try {
                    // the download happens in another thread
                    Intent i = new Intent(MusicService.ACTION_URL);
                    Uri uri = Uri.parse(mAdapter.getItem(position).getAudioURL());
                    i.setData(uri);
                    getActivity().startService(i);

                } catch (Exception e) {
                    Log.e("BookManagerActivity", "Error on attempt to download", e);
                }

                mQuickAction.dismiss();
            }
        });

        mQuickAction.addActionItem(playAction);
    }

    if (resource.getReadURL() != null) {
        readAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Read " + text, Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(getActivity(), ArticleActivity.class);
                if (resource.getReadURL() != null) {
                    intent.putExtra("url", resource.getReadURL());
                    intent.putExtra("verse", resource.getResourceVerse());
                    startActivity(intent);
                }

                mQuickAction.dismiss();
            }
        });
        mQuickAction.addActionItem(readAction);
    }

    mQuickAction.setAnimStyle(QuickActionVertical.ANIM_AUTO);

    mQuickAction.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss() {
        }
    });

    mQuickAction.show();
}

From source file:org.crossconnect.bible.activity.main.ResourceFragment.java

@Override
public void onListItemClick(ListView l, View v, int pos, long id) {

    final int position = pos;

    //Get the corresponding resource
    final OnlineAudioResource resource = mAdapter.getItem(position);

    final ActionItem readAction = new ActionItem();

    readAction.setTitle("Read");
    readAction.setIcon(getResources().getDrawable(R.drawable.icon_read));

    final ActionItem playAction = new ActionItem();

    playAction.setTitle("Play");
    playAction.setIcon(getResources().getDrawable(R.drawable.icon_play));

    final ActionItem downloadAction = new ActionItem();

    downloadAction.setTitle("Download");
    downloadAction.setIcon(getResources().getDrawable(R.drawable.icon_download));

    final QuickActionHorizontal mQuickAction = new QuickActionHorizontal(v);

    if (resource.getReadURL() != null) {
        readAction.setOnClickListener(new OnClickListener() {
            @Override//from  www  .  jav a2  s . c  om
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ArticleActivity.class);
                if (resource.getReadURL() != null) {
                    intent.putExtra("url", resource.getReadURL());
                    intent.putExtra("verse", resource.getResourceVerse());
                    startActivity(intent);
                }

                mQuickAction.dismiss();
            }
        });
        mQuickAction.addActionItem(readAction);
    }

    //Check the links are actually there
    if (resource.getAudioURL() != null) {
        downloadAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                final String RESOURCE_FOLDER = "/CrossConnectAudio/";
                Toast.makeText(getActivity(), "Downloading Audio for " + resource.getResourceName(),
                        Toast.LENGTH_SHORT).show();
                Log.d(TAG, "Downloading Audio " + mAdapter.getItem(position).getResourceName() + "from "
                        + mAdapter.getItem(position).getAudioURL());

                Request request = new Request(Uri.parse(resource.getAudioURL()));
                File path = new File(
                        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
                                + RESOURCE_FOLDER);
                path.mkdir();

                String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS)
                        + RESOURCE_FOLDER + FileUtil.getFileName(mAdapter.getItem(position), bibleText);

                resourceService.insertUpdate(mAdapter.getItem(position), filePath, bibleText);

                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PODCASTS,
                        RESOURCE_FOLDER + FileUtil.getFileName(mAdapter.getItem(position), bibleText));

                enqueue = dm.enqueue(request);

                mQuickAction.dismiss();
            }
        });
        mQuickAction.addActionItem(downloadAction);

        playAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Streaming Audio for " + resource.getResourceName(),
                        Toast.LENGTH_SHORT).show();
                Log.d(TAG, "Streaming Audio" + mAdapter.getItem(position).getResourceName() + "from "
                        + mAdapter.getItem(position).getAudioURL());
                try {
                    // the download happens in another thread
                    Intent i = new Intent(MusicService.ACTION_URL);
                    Uri uri = Uri.parse(mAdapter.getItem(position).getAudioURL());
                    i.setData(uri);
                    getActivity().startService(i);

                } catch (Exception e) {
                    Log.d("BookManagerActivity", "Error on attempt to download", e);
                }

                mQuickAction.dismiss();
            }
        });

        mQuickAction.addActionItem(playAction);
    }

    mQuickAction.setAnimStyle(QuickActionVertical.ANIM_AUTO);

    mQuickAction.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss() {
        }
    });

    mQuickAction.show();
}

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 va 2  s  . c om*/
        throw new IllegalArgumentException("Invalid directory representation: " + name);
    }
}

From source file:com.workingagenda.democracydroid.Adapters.ViewHolders.EpisodeViewHolder.java

@RequiresApi(api = Build.VERSION_CODES.M)
private void Download(String url, String title, String desc) {
    if (ContextCompat.checkSelfPermission(itemView.getContext(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ((Activity) itemView.getContext())
                .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
        // TODO: catch onRequestPermissionsResult
    } else {//w  w w  .  j av a2  s.co  m
        if ("http://democracynow.videocdn.scaleengine.net/democracynow-iphone/play/democracynow/playlist.m3u8"
                .equals(url)) {
            Toast toast = Toast.makeText(itemView.getContext(), "You can't download the Live Stream",
                    Toast.LENGTH_LONG);
            toast.show();
            return;
        }
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
        request.setDescription(desc);
        request.setTitle(title);
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

        String fileext = url.substring(url.lastIndexOf('/') + 1);
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PODCASTS, fileext);
        //http://stackoverflow.com/questions/24427414/getsystemservices-is-undefined-when-called-in-a-fragment

        // get download service and enqueue file
        DownloadManager manager = (DownloadManager) itemView.getContext()
                .getSystemService(Context.DOWNLOAD_SERVICE);
        manager.enqueue(request);
        // TODO: Save que ID for cancel button
        Toast toast = Toast.makeText(itemView.getContext(), "Starting download of " + title, Toast.LENGTH_LONG);
        toast.show();
    }
}

From source file:jupiter.broadcasting.live.holo.JBPlayer.java

public boolean HasIt(String mTitle, int AV) {
    String ext = (AV == 0) ? ".mp3" : ".mp4";
    File fileList = new File(
            Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PODCASTS + "/JB");
    File[] filenames = fileList.listFiles();
    if (filenames != null) {
        for (File tmpf : filenames) {
            if (tmpf.toString().contains(mTitle + ext)) {
                return true;
            }/*from ww  w . j a  va2s. c o m*/
        }
    }
    return false;
}

From source file:jupiter.broadcasting.live.holo.JBPlayer.java

public void DownLoad(String url) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    String ver = (av == 0) ? getString(R.string.audio) : getString(R.string.video);
    request.setDescription(getString(R.string.progress) + "(" + ver + ")...");
    request.setTitle(getIntent().getStringExtra("title"));

    down.setClickable(false);//from w  w w  .  j a v  a2  s.com

    // in order for this if to run, you must use the android 3.2 to compile your app
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    String ext = (av == 0) ? "mp3" : "mp4";
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PODCASTS + "/JB",
            getIntent().getStringExtra("title") + "." + ext);

    // get download service and enqueue file
    final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    final long enqueue = manager.enqueue(request);

    //register receiver to be notified when download finishes
    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(enqueue);
                Cursor c = manager.query(query);
                if (c != null) {
                    if (c.moveToFirst()) {
                        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                        if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                            Toast.makeText(getBaseContext(), "Finished", Toast.LENGTH_LONG).show();
                            hasit = true;
                            down.setClickable(true);
                        }
                    }
                }
            }
        }
    };

    registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:jupiter.broadcasting.live.holo.JBPlayer.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    //if nothing is selected (system calls this), do nothing
    if (av != position) {
        //if change occurs to AV spinner, reset the previous player
        if (mp != null && mp.isPlaying())
            mp.stop();/*from w  w w .j  a va 2  s  . c  o m*/
        if (videoView != null && videoView.isPlaying()) {
            videoView.suspend();
            videoView.setVisibility(View.GONE);
        }

        play.setEnabled(true);
        //play.setClickable(true);
        if (position != 0) {
            theLink = vLink;
        } else
            theLink = aLink;
        av = position;

        if (!offline) {
            hasit = HasIt(title, av);
            if (!hasit)
                down.setVisibility(View.VISIBLE);
            else {
                down.setVisibility(View.INVISIBLE);
                String ext = (av == 0) ? ".mp3" : ".mp4";
                theLink = Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PODCASTS
                        + "/JB/" + title + ext;
            }
        }
    }
}