List of usage examples for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE
String ACTION_MEDIA_SCANNER_SCAN_FILE
To view the source code for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE.
Click Source Link
From source file:org.apache.cordova.plugin.AMImageDownloader.java
private void savePhoto(Bitmap bmp) { OutputStream fOut = null;/*from w ww .j a v a 2 s. c o m*/ Calendar c = Calendar.getInstance(); String date = String.valueOf((c.get(Calendar.MONTH))) + String.valueOf((c.get(Calendar.DAY_OF_MONTH))) + String.valueOf((c.get(Calendar.YEAR))) + String.valueOf((c.get(Calendar.HOUR_OF_DAY))) + String.valueOf((c.get(Calendar.MINUTE))) + String.valueOf((c.get(Calendar.SECOND))); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), date.toString() + ".png"); try { fOut = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut); fOut.flush(); fOut.close(); /**Update image to gallery**/ Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(file); mediaScanIntent.setData(contentUri); this.cordova.getActivity().sendBroadcast(mediaScanIntent); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.manning.androidhacks.hack037.MainActivity.java
public void onLoop2Click(View v) { if (!canWriteInExternalStorage()) { Toast.makeText(this, "Can't write file", Toast.LENGTH_SHORT).show(); return;//from w ww. ja v a 2 s . co m } MediaUtils.saveRaw(this, R.raw.loop2, LOOP2_PATH); Uri uri = Uri.parse("file://" + LOOP2_PATH); Intent i = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri); sendBroadcast(i); }
From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java
public static void addImageToGallery(Context c, Uri contentUri) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(contentUri); c.sendBroadcast(mediaScanIntent);//from w w w . j ava 2 s . c om }
From source file:com.pimp.companionforband.fragments.extras.CameraActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera); int permissionCheck = ContextCompat.checkSelfPermission(CameraActivity.this, Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_DENIED) { Toast.makeText(CameraActivity.this, getString(R.string.camera_permission), Toast.LENGTH_LONG).show(); startActivity(new Intent(getApplicationContext(), MainActivity.class)); return;/*from w w w .j a v a 2s. c o m*/ } surfaceView = (SurfaceView) findViewById(R.id.surfaceView); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); SharedPreferences s = getApplicationContext().getSharedPreferences("MyPrefs", 0); final String location = s.getString("pic_location", "/storage/emulated/0/CompanionForBand/Camera"); jpegCallback = new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { FileOutputStream outStream = null; try { File file = new File(location); if (!file.exists() && !file.isDirectory()) file.mkdirs(); outStream = new FileOutputStream( location + File.separator + System.currentTimeMillis() + ".jpg"); outStream.write(data); outStream.close(); Intent scan = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri uri = Uri.fromFile(file); scan.setData(uri); sendBroadcast(scan); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { } Toast.makeText(getApplicationContext(), getString(R.string.picture_saved) + " " + location, Toast.LENGTH_SHORT).show(); refreshCamera(); } }; }
From source file:com.app.ecofriend.ecofriend.DisplayMessageActivity.java
private void launchMediaScanIntent() { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(imageUri);//from w ww . j a va 2s . com this.sendBroadcast(mediaScanIntent); }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
@NonNull private static String captureScreenshot(final Activity activity) { // Create the 'Screenshots' folder if it does not already exist File screenshotDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), SCREENSHOTS_DIR_NAME);// w w w . j a v a 2 s.c o m screenshotDir.mkdirs(); // Image name 'Screenshot_YearMonthDay-HourMinuteSecondMillisecond.png' Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); String imageName = "Screenshot_" + calendar.get(Calendar.YEAR) + (calendar.get(Calendar.MONTH) + 1) + calendar.get(Calendar.DAY_OF_MONTH); imageName += "-" + calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.MINUTE) + calendar.get(Calendar.SECOND) + calendar.get(Calendar.MILLISECOND) + ".png"; File screenshotFile = new File(screenshotDir, imageName); // Create the screenshot file try { if (screenshotFile.exists()) { screenshotFile.delete(); } screenshotFile.createNewFile(); } catch (IOException e) { Log.e(TAG, "Failed to create a new file", e); } // Capture the current screen View rootView = activity.getWindow().getDecorView().getRootView(); rootView.setDrawingCacheEnabled(true); Bitmap imageBitmap = Bitmap.createBitmap(rootView.getDrawingCache()); rootView.setDrawingCacheEnabled(false); FileOutputStream fos; try { fos = new FileOutputStream(screenshotFile); imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { Log.e(TAG, "Failed to write the bitmap to the file", e); } // Add the screenshot image to the Media Provider's database Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(screenshotFile); mediaScanIntent.setData(contentUri); activity.sendBroadcast(mediaScanIntent); return screenshotFile.getAbsolutePath(); }
From source file:com.joeyturczak.jtscanner.utils.Utility.java
public static void createSpreadsheet(Context context, TodayData todayData) { List<String> headerRow = new ArrayList<String>(); headerRow.add(""); headerRow.add("Machine ID"); headerRow.add("Hot Box ID"); headerRow.add("Cold Box ID"); List<List> recordToAdd = new ArrayList<List>(); recordToAdd.add(headerRow);//www . ja v a 2 s. c om long currentDay = normalizeDate(System.currentTimeMillis()); List<Asset> assets = todayData.getAssets(); String machine, hotBox, coldBox; for (Asset asset : assets) { List<String> nextRow = new ArrayList<>(); machine = asset.getMachine(); hotBox = asset.getHotBox(); coldBox = asset.getColdBox(); nextRow.add(String.valueOf(assets.indexOf(asset) + 1)); nextRow.add(machine); nextRow.add(hotBox); nextRow.add(coldBox); recordToAdd.add(nextRow); } CreateExcelSpreadsheet cls = new CreateExcelSpreadsheet(recordToAdd); try { deleteFilesOnDate(context, currentDay); Uri fileUri = cls.createExcelFile(); context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.henryco.opalette.api.utils.Utils.java
public static File updGallery(File outputFile, Context activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); final Uri contentUri = Uri.fromFile(outputFile); scanIntent.setData(contentUri);/* ww w . j a v a 2 s . co m*/ activity.sendBroadcast(scanIntent); } else activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); return outputFile; }
From source file:com.my.seams_carv.StartActivity.java
/** * The callback function is called after taking a photo. */// w ww . j a v a2s. co m private void onTakePhoto(int resultCode, Intent data) { if (resultCode == RESULT_CANCELED) return; final File file = new File(mPhotoPath.getPath()); final Uri uri = mPhotoPath; if (file.exists()) { mShowPhotoTask = Observable.create(new ObservableOnSubscribe<Void>() { @Override public void subscribe(ObservableEmitter<Void> e) throws Exception { // showPhoto(uri); openPhotoEditor(uri); } }).subscribeOn(AndroidSchedulers.mainThread()); } else { mPhotoPath = null; Snackbar.make(findViewById(android.R.id.content), "The picture doesn't exist.", Snackbar.LENGTH_SHORT) .show(); } // Add the photo to the system MediaContent. sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE).setData(uri)); }
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);/*from w ww . ja va2 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/"); //} }