List of usage examples for android.media MediaScannerConnection scanFile
public static void scanFile(Context context, String[] paths, String[] mimeTypes, OnScanCompletedListener callback)
From source file:com.slownet5.pgprootexplorer.utils.FileUtils.java
public static void notifyChange(Context ctx, String... path) { Log.d(TAG, "notifyChange: notifying change"); MediaScannerConnection.scanFile(ctx, path, null, new MediaScannerConnection.OnScanCompletedListener() { @Override/*from ww w .java 2s . com*/ public void onScanCompleted(String path, Uri uri) { Log.d(TAG, "onScanCompleted: scan completed: " + path); } }); }
From source file:com.commonsware.android.andshooter.ScreenshotService.java
void processImage(final byte[] png) { new Thread() { @Override//from www . j a v a 2 s . co m public void run() { File output = new File(getExternalFilesDir(null), "screenshot.png"); try { FileOutputStream fos = new FileOutputStream(output); fos.write(png); fos.flush(); fos.getFD().sync(); fos.close(); MediaScannerConnection.scanFile(ScreenshotService.this, new String[] { output.getAbsolutePath() }, new String[] { "image/png" }, null); } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception writing out screenshot", e); } } }.start(); beeper.startTone(ToneGenerator.TONE_PROP_ACK); stopCapture(); }
From source file:org.bienvenidoainternet.app.ViewerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { File baiDir = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/"); if (!baiDir.exists()) { baiDir.mkdir();// www .ja v a 2 s . c o m } if (item.getItemId() == R.id.menu_save_img) { BoardItemFile boardItemFile = fileList.get(imagePager.getCurrentItem()); File to = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/" + boardItemFile.file); ContextWrapper cw = new ContextWrapper(getApplicationContext()); File directory = cw.getDir("src", Context.MODE_PRIVATE); File fileSource = new File(directory, boardItemFile.boardDir + "_" + boardItemFile.file); try { InputStream in = new FileInputStream(fileSource); OutputStream out = new FileOutputStream(to); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); Toast.makeText(getApplicationContext(), boardItemFile.file + " guardado.", Toast.LENGTH_LONG) .show(); MediaScannerConnection.scanFile(this, new String[] { to.getPath() }, new String[] { "image/jpeg" }, null); } catch (Exception e) { e.printStackTrace(); } } if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); }
From source file:com.kunze.androidlocaltodo.TaskListActivity.java
private void BackupDatabase() { String loc = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/AndroidLocalTodoBackup.db"; try {/*from w w w .j a v a 2 s. com*/ mDB.BackupDatabase(loc); String[] paths = { loc }; MediaScannerConnection.scanFile(this, paths, null, null); AlertDialog.Builder builder = new AlertDialog.Builder(TaskListActivity.this); AlertDialog dlg = builder.setTitle("Success!").setMessage("Database backed up!").create(); dlg.show(); } catch (java.io.IOException e) { AlertDialog.Builder builder = new AlertDialog.Builder(TaskListActivity.this); AlertDialog dlg = builder.setTitle("File I/O error!").setMessage(e.getMessage()).create(); dlg.show(); } }
From source file:simonlang.coastdove.usagestatistics.utility.FileHelper.java
/** * Lets the media scanner scan any files given * @param paths Absolute paths of the files to scan *///from ww w .ja v a2 s. co m public static void scanFile(Context context, String... paths) { MediaScannerConnection.scanFile(context, paths, null, new MediaScannerConnection.MediaScannerConnectionClient() { @Override public void onMediaScannerConnected() { } @Override public void onScanCompleted(String path, Uri uri) { Log.v("Media scanner", "Scanned file: " + path); } }); }
From source file:com.jigarmjoshi.service.task.UploaderTask.java
private final boolean uploadEntryReport(Report entry) { if (entry == null || entry.getUploaded()) { return true; }/*from ww w . j a va2s .c om*/ boolean resultFlag = false; try { Log.i(UploaderTask.class.getSimpleName(), "uploading " + entry.getImageFileName()); Bitmap bm = BitmapFactory.decodeFile(entry.getImageFileName()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 60, bos); byte[] data = bos.toByteArray(); HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(this.serverUrl + "/uploadEntryRecord"); ByteArrayBody bab = new ByteArrayBody(data, "report.jpg"); // File file= new File("/mnt/sdcard/forest.png"); // FileBody bin = new FileBody(file); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("lat", new StringBody(Utility.encode(entry.getLat()))); reqEntity.addPart("lon", new StringBody(Utility.encode(entry.getLon()))); reqEntity.addPart("priority", new StringBody(Utility.encode(entry.getPriority()))); reqEntity.addPart("fileName", new StringBody(Utility.encode(entry.getImageFileName()))); reqEntity.addPart("reporterId", new StringBody(Utility.encode(entry.getId()))); reqEntity.addPart("uploaded", bab); postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder responseString = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { responseString = responseString.append(sResponse); } Log.i(UploaderTask.class.getSimpleName(), responseString.toString()); if ("SUCCESS".equalsIgnoreCase(responseString.toString())) { resultFlag = true; if (entry.getImageFileName() != null) { File imageFileToDelete = new File(entry.getImageFileName()); boolean deleted = imageFileToDelete.delete(); if (deleted) { Log.i(UploaderTask.class.getSimpleName(), "deleted = ?" + deleted); MediaScannerConnection.scanFile(context, new String[] { imageFileToDelete.getAbsolutePath() }, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { } }); } } } } catch (Exception ex) { Log.e(UploaderTask.class.getSimpleName(), "failed to upload", ex); resultFlag = false; } return resultFlag; }
From source file:com.jigarmjoshi.ReportFragment.java
private File getImageFile() { String path = Environment.getExternalStorageDirectory().toString(); File dir = new File(path, "/cleanup-India/media/cleanup-India/"); if (!dir.isDirectory()) { dir.mkdirs();/*from w w w. j a v a 2s. c om*/ } File file = new File(dir, String.valueOf(System.currentTimeMillis()) + ".jpg"); String imagePath = file.getAbsolutePath(); lastImagePath = imagePath; // scan the image so show up in album MediaScannerConnection.scanFile(rootView.getContext(), new String[] { imagePath }, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { } }); return file; }
From source file:io.realm.scanner.MainActivity.java
private void copyTestAssetIfNeeded() { String imagePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + TEST_IMAGE; if (new File(imagePath).exists()) { return;/*from w ww .j av a 2s. c om*/ } AssetManager assetManager = getAssets(); try { InputStream in = assetManager.open(TEST_IMAGE); OutputStream out = new FileOutputStream(imagePath); byte[] buffer = new byte[PRIME_NUMBER_1000th]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); out.flush(); out.close(); MediaScannerConnection.scanFile(this, new String[] { imagePath }, new String[] { "image/jpeg" }, null); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.potterpcs.recipebook.RecipeListFragment.java
public void onExportItemSelected(MenuItem item) { RecipeData data = ((RecipeBook) getActivity().getApplication()).getData(); try {//from www . j a v a 2 s.c o m String filename = data.exportRecipes(getItemIds()); if (filename != null) { // Log.v(TAG, "Exported to " + filename); MediaScannerConnection.scanFile(getActivity(), new String[] { filename }, null, null); } else { // Log.e(TAG, "Unable to export recipes"); } } catch (IOException e) { // Log.e(TAG, e.toString()); } }
From source file:org.mobisocial.corral.CorralDownloadClient.java
Uri doMediaScan(Uri content) { String[] paths = new String[] { content.getPath() }; MediaScannerConnection.scanFile(mContext, paths, null, null); return content; }