List of usage examples for android.os Environment DIRECTORY_DOWNLOADS
String DIRECTORY_DOWNLOADS
To view the source code for android.os Environment DIRECTORY_DOWNLOADS.
Click Source Link
From source file:org.botlibre.sdk.activity.graphic.GraphicActivity.java
public void downloadFile(View v) { if (gInstance.fileName.equals("")) { MainActivity.showMessage("Missing file!", this); return;/*from www . j a v a 2 s . c o m*/ } String url = MainActivity.WEBSITE + "/" + gInstance.media; try { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle(gInstance.fileName); request.setDescription(MainActivity.WEBSITE); // request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); only download thro wifi. request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); Toast.makeText(GraphicActivity.this, "Downloading " + gInstance.fileName, Toast.LENGTH_SHORT).show(); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, gInstance.fileName); DownloadManager manager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE); BroadcastReceiver onComplete = new BroadcastReceiver() { public void onReceive(Context ctxt, Intent intent) { Toast.makeText(GraphicActivity.this, gInstance.fileName + " Downloaded!", Toast.LENGTH_SHORT) .show(); } }; manager.enqueue(request); registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } catch (Exception e) { MainActivity.showMessage(e.getMessage(), this); } }
From source file:ufms.br.com.ufmsapp.task.DownloadTask.java
@Override protected String doInBackground(String... sUrl) { InputStream input = null;// w w w . j a v a 2s . c o m OutputStream output = null; HttpURLConnection connection = null; try { URL url = new URL(sUrl[0]); connection = (HttpURLConnection) url.openConnection(); connection.connect(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { return "Server returned HTTP " + connection.getResponseCode() + " " + connection.getResponseMessage(); } int fileLength = connection.getContentLength(); input = connection.getInputStream(); output = new FileOutputStream(new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName)); byte data[] = new byte[4096]; long total = 0; int count; while ((count = input.read(data)) != -1) { if (isCancelled()) { input.close(); return null; } total += count; if (fileLength > 0) publishProgress((int) (total * 100 / fileLength)); output.write(data, 0, count); } } catch (Exception e) { return e.toString(); } finally { try { if (output != null) output.close(); if (input != null) input.close(); } catch (IOException ignored) { } if (connection != null) connection.disconnect(); } return null; }
From source file:de.k3b.android.toGoZip.SettingsImpl.java
@TargetApi(Build.VERSION_CODES.KITKAT) private static File getRootDir44() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); }
From source file:com.example.healthplus.wifidirect.DeviceDetailFragment.java
public void sendFile() { String localIP = Utils.getLocalIPAddress(); // Trick to find the ip in the file /proc/net/arp String client_mac_fixed = new String(device.deviceAddress).replace("3a", "38"); Log.d(WiFiDirectActivity.TAG, "Client MAC fixed Richa: " + client_mac_fixed); String clientIP = Utils.getIPFromMac(client_mac_fixed); Log.d(WiFiDirectActivity.TAG, "Local IP Address Richa: " + localIP); Log.d(WiFiDirectActivity.TAG, "Client IP Address Richa: " + clientIP); // User has picked an image. Transfer it to group owner i.e peer using // FileTransferService. File root = android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); String path = root.getAbsolutePath() + "/healthplus/" + "request.json"; //Uri uri = new Uri.Builder().appendPath(path); //Log.d(WiFiDirectActivity.TAG, "URI richa: " + uri); TextView statusText = (TextView) mContentView.findViewById(R.id.status_text); statusText.setText("Sending: " + path); //Log.d(WiFiDirectActivity.TAG, "Intent----------- " + uri); Intent serviceIntent = new Intent(getActivity(), FileTransferService.class); Log.d(WiFiDirectActivity.TAG, "Reached here Richa before send"); serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE); //Log.d(WiFiDirectActivity.TAG, "Reached here Richa after send"); //Log.d(WiFiDirectActivity.TAG, "Path : " + path); serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, path); Log.d(WiFiDirectActivity.TAG, "Reached here Richa: put extra string to URI"); Log.d(WiFiDirectActivity.TAG, "Reached here Richa after send"); Log.d(WiFiDirectActivity.TAG, "Reached here Richa IP server =" + IP_SERVER); Log.d(WiFiDirectActivity.TAG, "Reached here Richa LOCAL IP =" + localIP); if (localIP.equals(IP_SERVER)) { Log.d(WiFiDirectActivity.TAG, "Reached here client IP1:" + clientIP); serviceIntent.putExtra(FileTransferService.EXTRAS_ADDRESS, clientIP); Log.d(WiFiDirectActivity.TAG, "Reached here client IP2:" + clientIP); } else {/*from ww w .j a v a 2 s.c o m*/ Log.d(WiFiDirectActivity.TAG, "Reached here IP server1:" + IP_SERVER); serviceIntent.putExtra(FileTransferService.EXTRAS_ADDRESS, IP_SERVER); Log.d(WiFiDirectActivity.TAG, "Reached here Extra address2:" + IP_SERVER); } serviceIntent.putExtra(FileTransferService.EXTRAS_PORT, PORT); Log.d(WiFiDirectActivity.TAG, "Reached here Richa service started"); getActivity().startService(serviceIntent); }
From source file:ufms.br.com.ufmsapp.fragment.MateriaisDisciplinaFragment.java
private void openDocument(String path) { String fileName = path.replace(DownloadTask.UPLOAD_PATH_REPLACE, ""); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);//w w w . j a va 2s . c o m intent.setDataAndType(Uri.fromFile(file), GetFileMimeType.getMimeType(fileName)); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); }
From source file:uk.co.senab.photoview.sample.SimpleSampleActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_zoom_toggle: mAttacher.setZoomable(!mAttacher.canZoom()); return true; case R.id.menu_scale_fit_center: mAttacher.setScaleType(ScaleType.FIT_CENTER); return true; case R.id.menu_scale_fit_start: mAttacher.setScaleType(ScaleType.FIT_START); return true; case R.id.menu_scale_fit_end: mAttacher.setScaleType(ScaleType.FIT_END); return true; case R.id.menu_scale_fit_xy: mAttacher.setScaleType(ScaleType.FIT_XY); return true; case R.id.menu_scale_scale_center: mAttacher.setScaleType(ScaleType.CENTER); return true; case R.id.menu_scale_scale_center_crop: mAttacher.setScaleType(ScaleType.CENTER_CROP); return true; case R.id.menu_scale_scale_center_inside: mAttacher.setScaleType(ScaleType.CENTER_INSIDE); return true; case R.id.menu_scale_random_animate: case R.id.menu_scale_random: Random r = new Random(); float minScale = mAttacher.getMinimumScale(); float maxScale = mAttacher.getMaximumScale(); float randomScale = minScale + (r.nextFloat() * (maxScale - minScale)); mAttacher.setScale(randomScale, item.getItemId() == R.id.menu_scale_random_animate); showToast(String.format(SCALE_TOAST_STRING, randomScale)); return true; case R.id.menu_matrix_restore: if (mCurrentDisplayMatrix == null) showToast("You need to capture display matrix first"); else//from ww w . j av a 2s .co m mAttacher.setDisplayMatrix(mCurrentDisplayMatrix); return true; case R.id.menu_matrix_capture: mAttacher.getDisplayMatrix(mCurrentDisplayMatrix); return true; case R.id.extract_visible_bitmap: try { Bitmap bmp = mAttacher.getVisibleRectangleBitmap(); File tmpFile = File.createTempFile("photoview", ".png", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)); FileOutputStream out = new FileOutputStream(tmpFile); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/png"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile)); startActivity(share); Toast.makeText(this, String.format("Extracted into: %s", tmpFile.getAbsolutePath()), Toast.LENGTH_SHORT).show(); } catch (Throwable t) { t.printStackTrace(); Toast.makeText(this, "Error occured while extracting bitmap", Toast.LENGTH_SHORT).show(); } return true; } return super.onOptionsItemSelected(item); }
From source file:org.que.activities.fragments.PaperDetailMenuFragment.java
/** * @author deLaczkovich on 26.06.2014./*from w ww .j a v a 2 s . c o m*/ * @param item * @return */ @Override public boolean onOptionsItemSelected(MenuItem item) { Date d = new Date(); if (item.getItemId() == R.id.action_paper_detail) { long startDate = Long.parseLong(getString(R.string.startDate)); if (d.getTime() < startDate) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(getString(R.string.notAvailable)); builder.setNeutralButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); return super.onOptionsItemSelected(item); } String key = getString(R.string.pref_api_key); SharedPreferences pref = getActivity().getSharedPreferences(PaperDetailMenuFragment.class.getName(), Context.MODE_PRIVATE); final String apiKey = pref.getString(key, null); if (apiKey == null) { DialogFragment auth_required = new AuthRequiredDialogFragment(); auth_required.show(getActivity().getSupportFragmentManager(), AuthRequiredDialogFragment.TAG_AUTH_REQUIRED); Toast.makeText(getActivity(), getString(R.string.authSuccess), Toast.LENGTH_LONG).show(); } else { //TODO Paper detail view call AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getString(R.string.viewQuestionTitle)) .setMessage(getString(R.string.viewQuestionMsg)) .setPositiveButton(getString(R.string.pdfViewerAvail), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DownloadManager downloadManager = (DownloadManager) getActivity() .getSystemService(Context.DOWNLOAD_SERVICE); String url = String.format(getString(R.string.alert_paper_view_url_direct), paper.getId(), apiKey); Uri Download_Uri = Uri.parse(url); String fileName = paper.getTitle() + ".pdf"; DownloadManager.Request request = new DownloadManager.Request(Download_Uri) .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI) .setTitle(getString(R.string.paperDwnlTitle)) .setDescription(getString(R.string.paperDwnlMsg)) .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) .setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); downloadManager.enqueue(request); } }) .setNegativeButton(getString(R.string.noPdfViewerAvail), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Bundle args = new Bundle(); String url = String.format(getString(R.string.alert_paper_view_url), paper.getId(), apiKey); args.putString(WebviewFragment.ARG_WEBVIEW_FRAGMENT_URL, url); args.putString(WebviewFragment.ARG_WEBVIEW_FRAGMENT_TITLE, paper.getTitle()); Fragment fragment = new WebviewFragment(); fragment.setArguments(args); FragmentManager mgr = ((FragmentActivity) getActivity()) .getSupportFragmentManager(); Fragment old = mgr.findFragmentById(R.id.content_frame); FragmentTransaction trx = mgr.beginTransaction(); if (old != null) { trx.remove(old); } trx.add(R.id.content_frame, fragment).addToBackStack(null).commit(); } }) .show(); } } return super.onOptionsItemSelected(item); }
From source file:ufms.br.com.ufmsapp.fragment.MateriaisEventoFragment.java
@Override public void onMaterialClick(View v, int position, final Material material) { if (RequestPermission.verifyStoragePermissions(getActivity())) { String fileName = material.getPathMaterial().replace(DownloadTask.UPLOAD_PATH_REPLACE, ""); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);//from w w w . ja va2 s . c om switch (v.getId()) { case R.id.root_open_document: if (file.exists()) { openDocument(material.getPathMaterial()); } else { final DownloadTask downloadTask = new DownloadTask(getActivity(), R.mipmap.ic_file_download_black_24dp, material.getPathMaterial(), getActivity().getResources().getString(R.string.txt_download_em_progresso), getActivity()); downloadTask.execute(UrlEndpoints.URL_ENDPOINT_DOWNLOAD_FILE + material.getPathMaterial()); openDocument(material.getPathMaterial()); } break; case R.id.btn_file_download: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean networkTypeWifi = prefs.getBoolean(getResources().getString(R.string.pref_network_type), true); //Se existir o arquivo, no baixa novamente if (!file.exists()) { if (ConnectionUtils.isConnectedWifi(getActivity())) { final DownloadTask downloadTask = new DownloadTask(getActivity(), R.mipmap.ic_file_download_black_24dp, material.getPathMaterial(), getActivity().getResources().getString(R.string.txt_download_em_progresso), getActivity()); downloadTask.execute(UrlEndpoints.URL_ENDPOINT_DOWNLOAD_FILE + material.getPathMaterial()); } else if (ConnectionUtils.isConnectedMobile(getActivity()) && !networkTypeWifi) { final DownloadTask downloadTask = new DownloadTask(getActivity(), R.mipmap.ic_file_download_black_24dp, material.getPathMaterial(), getActivity().getResources().getString(R.string.txt_download_em_progresso), getActivity()); downloadTask.execute(UrlEndpoints.URL_ENDPOINT_DOWNLOAD_FILE + material.getPathMaterial()); } else { Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.txt_wifi_only_snackbar, Snackbar.LENGTH_LONG).show(); } } else { final Snackbar snackbar = Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.txt_success_download_snack_bar, Snackbar.LENGTH_LONG); snackbar.setAction(R.string.txt_open_document, new View.OnClickListener() { @Override public void onClick(View v) { openDocument(material.getPathMaterial()); } }).show(); //Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.txt_success_download_snack_bar, Snackbar.LENGTH_LONG).show(); } break; } } else { Toast.makeText(MyApplication.getAppContext(), "Para baixar os materiais, ative a permisso", Toast.LENGTH_LONG).show(); } }
From source file:ufms.br.com.ufmsapp.fragment.MateriaisDisciplinaFragment.java
@Override public void onMaterialClick(View v, int position, final Material material) { if (RequestPermission.verifyStoragePermissions(getActivity())) { String fileName = material.getPathMaterial().replace(DownloadTask.UPLOAD_PATH_REPLACE, ""); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);/*from ww w.j a v a 2 s . c om*/ switch (v.getId()) { case R.id.root_open_document: if (file.exists()) { openDocument(material.getPathMaterial()); } else { final DownloadTask downloadTask = new DownloadTask(getActivity(), R.mipmap.ic_file_download_black_24dp, material.getPathMaterial(), getActivity().getResources().getString(R.string.txt_download_em_progresso), getActivity()); downloadTask.execute(UrlEndpoints.URL_ENDPOINT_DOWNLOAD_FILE + material.getPathMaterial()); openDocument(material.getPathMaterial()); } break; case R.id.btn_file_download: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean networkTypeWifi = prefs.getBoolean(getResources().getString(R.string.pref_network_type), true); //Se existir o arquivo, no baixa novamente if (!file.exists()) { if (ConnectionUtils.isConnectedWifi(getActivity())) { final DownloadTask downloadTask = new DownloadTask(getActivity(), R.mipmap.ic_file_download_black_24dp, material.getPathMaterial(), getActivity().getResources().getString(R.string.txt_download_em_progresso), getActivity()); downloadTask.execute(UrlEndpoints.URL_ENDPOINT_DOWNLOAD_FILE + material.getPathMaterial()); } else if (ConnectionUtils.isConnectedMobile(getActivity()) && !networkTypeWifi) { final DownloadTask downloadTask = new DownloadTask(getActivity(), R.mipmap.ic_file_download_black_24dp, material.getPathMaterial(), getActivity().getResources().getString(R.string.txt_download_em_progresso), getActivity()); downloadTask.execute(UrlEndpoints.URL_ENDPOINT_DOWNLOAD_FILE + material.getPathMaterial()); } else { Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.txt_wifi_only_snackbar, Snackbar.LENGTH_LONG).show(); } } else { final Snackbar snackbar = Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.txt_success_download_snack_bar, Snackbar.LENGTH_LONG); snackbar.setAction(R.string.txt_open_document, new View.OnClickListener() { @Override public void onClick(View v) { openDocument(material.getPathMaterial()); } }).show(); } break; } } else { Toast.makeText(MyApplication.getAppContext(), "Para baixar os materiais, ative a permisso", Toast.LENGTH_LONG).show(); } }
From source file:org.catrobat.catroid.ui.WebViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); ActionBar actionBar = getActionBar(); actionBar.hide();//from w w w . j a va 2 s. c o m Intent intent = getIntent(); url = intent.getStringExtra(INTENT_PARAMETER_URL); if (url == null) { url = Constants.BASE_URL_HTTPS; } callingActivity = intent.getStringExtra(CALLING_ACTIVITY); webView = (WebView) findViewById(R.id.webView); webView.setBackgroundColor( ResourcesCompat.getColor(getResources(), R.color.application_background_color, null)); webView.setWebViewClient(new MyWebViewClient()); webView.getSettings().setJavaScriptEnabled(true); String language = String.valueOf(Constants.CURRENT_CATROBAT_LANGUAGE_VERSION); String flavor = Constants.FLAVOR_DEFAULT; String version = Utils.getVersionName(getApplicationContext()); String platform = Constants.PLATFORM_DEFAULT; webView.getSettings().setUserAgentString( "Catrobat/" + language + " " + flavor + "/" + version + " Platform/" + platform); webView.loadUrl(url); webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Log.d(WebViewActivity.class.getSimpleName(), "contentDisposition: " + contentDisposition + " " + mimetype); if (getExtensionFromContentDisposition(contentDisposition).contains(Constants.CATROBAT_EXTENSION)) { DownloadUtil.getInstance().prepareDownloadAndStartIfPossible(WebViewActivity.this, url); } else if (url.contains(Constants.LIBRARY_BASE_URL)) { String name = getMediaNameFromUrl(url); String mediaType = getMediaTypeFromContentDisposition(contentDisposition); String fileName = name + getExtensionFromContentDisposition(contentDisposition); String tempPath = null; switch (mediaType) { case Constants.MEDIA_TYPE_LOOK: tempPath = Constants.TMP_LOOKS_PATH; break; case Constants.MEDIA_TYPE_SOUND: tempPath = Constants.TMP_SOUNDS_PATH; } String filePath = Utils.buildPath(tempPath, fileName); resultIntent.putExtra(MEDIA_FILE_PATH, filePath); DownloadUtil.getInstance().prepareMediaDownloadAndStartIfPossible(WebViewActivity.this, url, mediaType, name, filePath, callingActivity); } else { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle(getString(R.string.notification_download_title_pending) + " " + DownloadUtil.getInstance().getProjectNameFromUrl(url)); request.setDescription(getString(R.string.notification_download_pending)); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, DownloadUtil.getInstance().getProjectNameFromUrl(url) + ANDROID_APPLICATION_EXTENSION); request.setMimeType(mimetype); registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); downloadManager.enqueue(request); } } }); }