Example usage for android.os Environment DIRECTORY_DOWNLOADS

List of usage examples for android.os Environment DIRECTORY_DOWNLOADS

Introduction

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

Prototype

String DIRECTORY_DOWNLOADS

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

Click Source Link

Document

Standard directory in which to place files that have been downloaded by the user.

Usage

From source file:no.digipost.android.utilities.FileUtilities.java

public static File getDownloadsStorageDir(String fileName) throws Exception {
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            fileName);// w w  w .  j a  v a  2 s.  co m
    try {
        file.createNewFile();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return file;
}

From source file:org.golang.app.WViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Fixed Portrait orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    /*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);*/

    setContentView(R.layout.webview);/*ww  w  .j  a  va  2 s  .c  o  m*/
    WebView webView = (WebView) findViewById(R.id.webView1);

    initWebView(webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d("JavaGoWV: ", url);

            final Pattern p = Pattern.compile("dcoinKey&password=(.*)$");
            final Matcher m = p.matcher(url);
            if (m.find()) {
                try {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                //File root = android.os.Environment.getExternalStorageDirectory();
                                File dir = Environment
                                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                                Log.d("JavaGoWV", "dir " + dir);

                                URL keyUrl = new URL(
                                        "http://127.0.0.1:8089/ajax?controllerName=dcoinKey&first=1"); //you can write here any link
                                //URL keyUrl = new URL("http://yandex.ru/"); //you can write here any link
                                File file = new File(dir, "dcoin-key.png");

                                long startTime = System.currentTimeMillis();
                                Log.d("JavaGoWV", "download begining");
                                Log.d("JavaGoWV", "download keyUrl:" + keyUrl);

                                /* Open a connection to that URL. */
                                URLConnection ucon = keyUrl.openConnection();

                                Log.d("JavaGoWV", "0");
                                /*
                                * Define InputStreams to read from the URLConnection.
                                */
                                InputStream is = ucon.getInputStream();

                                Log.d("JavaGoWV", "01");

                                BufferedInputStream bis = new BufferedInputStream(is);

                                Log.d("JavaGoWV", "1");
                                /*
                                * Read bytes to the Buffer until there is nothing more to read(-1).
                                */
                                ByteArrayBuffer baf = new ByteArrayBuffer(5000);
                                int current = 0;
                                while ((current = bis.read()) != -1) {
                                    baf.append((byte) current);
                                }

                                Log.d("JavaGoWV", "2");
                                /* Convert the Bytes read to a String. */
                                FileOutputStream fos = new FileOutputStream(file);
                                fos.write(baf.toByteArray());
                                fos.flush();
                                fos.close();

                                Log.d("JavaGoWV", "3");
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                                    Uri contentUri = Uri.fromFile(file);
                                    mediaScanIntent.setData(contentUri);
                                    WViewActivity.this.sendBroadcast(mediaScanIntent);
                                } else {
                                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                                            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
                                }

                                Log.d("JavaGoWV", "4");
                            } catch (Exception e) {
                                Log.e("JavaGoWV error 0", e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                    thread.start();

                } catch (Exception e) {
                    Log.e("JavaGoWV error", e.toString());
                    e.printStackTrace();
                }
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            Log.e("JavaGoWV", "shouldOverrideUrlLoading " + url);

            if (url.endsWith(".mp4")) {
                Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(in);
                return true;
            } else {
                return false;
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.d("JavaGoWV",
                    "failed: " + failingUrl + ", error code: " + errorCode + " [" + description + "]");
        }
    });

    SystemClock.sleep(1500);
    //if (MyService.DcoinStarted(8089)) {
    webView.loadUrl("http://localhost:8089/");
    //}

}

From source file:com.coinblesk.client.backup.BackupRestoreDialogFragment.java

private void initBackupFilesList() {
    File backupDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    File[] files = backupDir.listFiles(new FilenameFilter() {
        @Override/*w  w  w  . ja  v  a2  s. c o m*/
        public boolean accept(File dir, String filename) {
            return filename.startsWith(Constants.BACKUP_FILE_PREFIX);
        }
    });

    List<File> backupFiles = new ArrayList<>();
    if (files != null) {
        for (File f : files) {
            backupFiles.add(f);
        }
    }
    Collections.sort(backupFiles);
    ArrayAdapter<File> fileAdapter = new ArrayAdapter<>(getContext(), R.layout.simple_multiline_list_item,
            R.id.text1, backupFiles);
    backupFilesList.setAdapter(fileAdapter);
}

From source file:de.baumann.browser.popups.Popup_files.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(ContextCompat.getColor(Popup_files.this, R.color.colorThreeDark));

    setContentView(R.layout.activity_popup);
    helper_main.onStart(Popup_files.this);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit()/*from  w  w w . j a  v a 2 s.  c  om*/
            .putString("files_startFolder",
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())
            .apply();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    editText = (EditText) findViewById(R.id.editText);
    editText.setVisibility(View.GONE);
    editText.setHint(R.string.app_search_hint);
    editText.clearFocus();
    urlBar = (TextView) findViewById(R.id.urlBar);
    setTitle();

    listView = (ListView) findViewById(R.id.list);

    //calling Notes_DbAdapter
    db = new DbAdapter_Files(this);
    db.open();

    setFilesList();
}

From source file:com.sap.nwcloudmanager.api.LogAPI.java

public static void downloadLog(final Context context, final String appId, final String logName,
        final DownloadLogResponseHandler downloadLogResponseHandler) {

    NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance();
    getHttpClient().setBasicAuth(config.getUsername(), config.getPassword());
    String[] contentTypes = { "application/x-gzip" };
    getHttpClient().get("https://monitoring." + config.getHost() + "/log/api_basic/logs/" + config.getAccount()
            + "/" + appId + "/web/" + logName, null, new BinaryHttpResponseHandler(contentTypes) {

                /*//from   w  w w .  ja va  2 s. c  o m
                 * (non-Javadoc)
                 * 
                 * @see
                 * com.loopj.android.http.BinaryHttpResponseHandler#onSuccess(byte
                 * [])
                 */
                @Override
                public void onSuccess(byte[] arg0) {

                    GZIPInputStream gzis = null;

                    try {
                        gzis = new GZIPInputStream(new ByteArrayInputStream(arg0));

                        StringBuilder string = new StringBuilder();
                        byte[] data = new byte[4028];
                        int bytesRead;
                        while ((bytesRead = gzis.read(data)) != -1) {
                            string.append(new String(data, 0, bytesRead));
                        }

                        File downloadsFile = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
                        if (downloadsFile.exists()) {
                            downloadsFile = new File(
                                    context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
                                            .getAbsolutePath() + "/" + logName);
                            FileOutputStream fos = new FileOutputStream(downloadsFile);
                            fos.write(string.toString().getBytes());
                            fos.close();
                        }

                        downloadLogResponseHandler.onSuccess(downloadsFile.getAbsolutePath());

                    } catch (IOException e) {
                        Log.e(e.getMessage());
                    } finally {
                        try {
                            if (gzis != null) {
                                gzis.close();
                            }
                        } catch (IOException e) {
                        }
                    }
                }

                @Override
                public void onFailure(Throwable arg0) {
                    downloadLogResponseHandler.onFailure(arg0, arg0.getMessage());
                }

            });
}

From source file:me.kartikarora.transfersh.activities.DownloadActivity.java

private void beginDownload(String name, String type, String url) {
    mTracker.send(new HitBuilders.EventBuilder().setCategory("Action").setAction("Download : " + url).build());
    DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    Uri uri = Uri.parse(url);//from  w w  w.  j av a  2s  . co  m
    DownloadManager.Request request = new DownloadManager.Request(uri);
    request.setDescription(getString(R.string.app_name));
    request.setTitle(name);
    String dir = "/" + getString(R.string.app_name) + "/" + type + "/" + name;
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, dir);
    manager.enqueue(request);
}

From source file:com.projecttango.experiments.javapointcloud.PointCloudActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jpoint_cloud);
    setTitle(R.string.app_name);/* w  w  w .  jav  a  2  s  .  co m*/
    outFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "shoopdawoop.txt");
    if (!outFile.exists())
        try {
            outFile.createNewFile();
        } catch (IOException e1) {
            throw new AssertionError();
            // TODO Auto-generated catch block
        }
    mPoseTextView = (TextView) findViewById(R.id.pose);
    mQuatTextView = (TextView) findViewById(R.id.quat);
    mPoseCountTextView = (TextView) findViewById(R.id.posecount);
    mDeltaTextView = (TextView) findViewById(R.id.deltatime);
    mTangoEventTextView = (TextView) findViewById(R.id.tangoevent);
    mPoseStatusTextView = (TextView) findViewById(R.id.status);
    mPointCountTextView = (TextView) findViewById(R.id.pointCount);
    mTangoServiceVersionTextView = (TextView) findViewById(R.id.version);
    mApplicationVersionTextView = (TextView) findViewById(R.id.appversion);
    mAverageZTextView = (TextView) findViewById(R.id.averageZ);
    mFrequencyTextView = (TextView) findViewById(R.id.frameDelta);

    mFirstPersonButton = (Button) findViewById(R.id.first_person_button);
    mFirstPersonButton.setOnClickListener(this);
    mThirdPersonButton = (Button) findViewById(R.id.third_person_button);
    mThirdPersonButton.setOnClickListener(this);
    mTopDownButton = (Button) findViewById(R.id.top_down_button);
    mTopDownButton.setOnClickListener(this);

    mTango = new Tango(this);
    Log.d(TAG, "Tango constructed on activity context");

    mConfig = new TangoConfig();
    mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
    mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);

    int maxDepthPoints = mConfig.getInt("max_point_cloud_elements");
    mRenderer = new PCRenderer(maxDepthPoints);
    mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
    mGLView.setEGLContextClientVersion(2);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    PackageInfo packageInfo;
    try {
        packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
        mApplicationVersionTextView.setText(packageInfo.versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Display the version of Tango Service
    mServiceVersion = mConfig.getString("tango_service_library_version");
    mTangoServiceVersionTextView.setText(mServiceVersion);
    mIsTangoServiceConnected = false;

}

From source file:fiskinfoo.no.sintef.fiskinfoo.Http.BarentswatchApiRetrofit.BarentswatchApi.java

public BarentswatchApi() {
    String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
            .toString();/*  ww  w.jav a2s . c  o  m*/
    String fileName = directoryPath + "/FiskInfo/api_setting.json";
    File file = new File(fileName);
    String environment = null;

    if (file.exists()) {
        InputStream inputStream;
        InputStreamReader streamReader;
        JsonReader jsonReader;

        try {
            inputStream = new BufferedInputStream(new FileInputStream(file));
            streamReader = new InputStreamReader(inputStream, "UTF-8");
            jsonReader = new JsonReader(streamReader);

            jsonReader.beginObject();
            while (jsonReader.hasNext()) {
                String name = jsonReader.nextName();
                if (name.equals("environment")) {
                    environment = jsonReader.nextString();
                } else {
                    jsonReader.skipValue();
                }
            }
            jsonReader.endObject();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }

    targetProd = !"pilot".equals(environment);
    currentPath = targetProd ? barentsWatchProdAddress : barentsWatchPilotAddress;
    BARENTSWATCH_API_ENDPOINT = currentPath + "/api/v1/geodata";

    Executor httpExecutor = Executors.newSingleThreadExecutor();
    MainThreadExecutor callbackExecutor = new MainThreadExecutor();
    barentswatchApi = initializeBarentswatchAPI(httpExecutor, callbackExecutor);
}

From source file:com.metinkale.prayerapp.hadis.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hadis_main);

    mPrefs = getSharedPreferences("hadis", 0);
    mNumber = (TextView) findViewById(R.id.number);
    mLeft = (ImageView) findViewById(R.id.left);
    mRight = (ImageView) findViewById(R.id.right);
    mAdapter = new MyAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);/*from   www.  j a v  a2  s. c  o m*/

    mLeft.setOnClickListener(this);
    mRight.setOnClickListener(this);
    mNumber.setOnClickListener(this);

    loadFavs();
    try {
        setState(STATE_SHUFFLED);
    } catch (RuntimeException e) {
        Crashlytics.logException(e);
        finish();
        String lang = Prefs.getLanguage();
        if (lang.equals("ar"))
            lang = "en";
        new File(App.getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), lang + "/hadis.db")
                .delete();
        startActivity(new Intent(this, com.metinkale.prayerapp.vakit.Main.class));
    }
}

From source file:file_manager.Activity_files.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }/* www.  j ava  2 s  . c  o m*/

    PackageManager pm = getPackageManager();
    boolean isInstalled = isPackageInstalled("de.baumann.pdfcreator", pm);

    if (isInstalled) {
        PackageManager p = getPackageManager();
        p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("de.baumann.pdfcreator");
        LaunchIntent.setAction("pdf_openFolder");
        startActivity(LaunchIntent);
        finish();
    }

    setContentView(R.layout.activity_file_manager);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit()
            .putString("files_startFolder",
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())
            .apply();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    listView = (ListView) findViewById(R.id.listNotes);
    filter_layout = (RelativeLayout) findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    filter = (EditText) findViewById(R.id.myFilter);

    ImageButton ib_hideKeyboard = (ImageButton) findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            filter_layout.setVisibility(View.GONE);
            setFilesList();
        }
    });

    //calling Notes_DbAdapter
    db = new DbAdapter_Files(this);
    db.open();

    setTitle();
    setFilesList();
}