List of usage examples for android.media MediaScannerConnection scanFile
public static void scanFile(Context context, String[] paths, String[] mimeTypes, OnScanCompletedListener callback)
From source file:de.baumann.thema.FragmentSound.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.sound, container, false); setHasOptionsMenu(true);/* w w w . j a v a 2 s . c om*/ final String[] itemTITLE = { "Ouverture - Hymne" + " (Steven Testelin)" + " | " + getString(R.string.duration) + " 01:49", "Canon and Gigue in D major" + " | " + getString(R.string.duration) + " 00:45", "Epic" + " (Alexey Anisimov)" + " | " + getString(R.string.duration) + " 01:53", "Isn't it" + " | " + getString(R.string.duration) + " 00:01", "Jingle Bells Sms" + " | " + getString(R.string.duration) + " 00:04", "Wet" + " | " + getString(R.string.duration) + " 00:01", }; final String[] itemURL = { Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/hymne.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/canon.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/epic.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/isnt_it.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/jingle_bells_sms.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/wet.mp3", }; final String[] itemDES = { "CC license: https://www.jamendo.com/track/1004091/ouverture-hymne", "CC license: https://musopen.org/music/2672/johann-pachelbel/canon-and-gigue-in-d-major/", "CC license: https://www.jamendo.com/track/1344095/epic", "CC license: https://notificationsounds.com/standard-ringtones/isnt-it-524", "CC license: https://notificationsounds.com/message-tones/jingle-bells-sms-523", "CC license: https://notificationsounds.com/notification-sounds/wet-431", }; final String[] itemFN = { "hymne.mp3", "canon.mp3", "epic.mp3", "isnt_it.mp3", "jingle_bells_sms.mp3", "wet.mp3", }; CustomListAdapter_Sound adapter = new CustomListAdapter_Sound(getActivity(), itemTITLE, itemURL, itemDES, itemDES); listView = (ListView) rootView.findViewById(R.id.bookmarks); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub String Selecteditem = itemURL[+position]; final MediaPlayer mp = MediaPlayer.create(getActivity(), Uri.parse(Selecteditem)); mp.start(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { mp.stop(); } }, 5000); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final String SelecteditemMes = itemTITLE[+position]; final String Selecteditem = itemURL[+position]; final String SelecteditemTitle = itemFN[+position]; final String SelecteditemUrl = itemDES[+position].substring(12); final CharSequence[] options = { getString(R.string.set_ringtone), getString(R.string.set_notification), getString(R.string.set_alarm), getString(R.string.play), getString(R.string.open) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.set_ringtone))) { File directory_al = new File( Environment.getExternalStorageDirectory() + "/Ringtones/"); if (!directory_al.exists()) { directory_al.mkdirs(); } try { InputStream in; OutputStream out; in = new FileInputStream(Selecteditem); out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Ringtones/" + SelecteditemTitle); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); // write the output file out.flush(); out.close(); MediaScannerConnection.scanFile(getActivity(), new String[] { Environment.getExternalStorageDirectory() + "/Ringtones/" + SelecteditemTitle }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Intent intent2 = new Intent(Settings.ACTION_SOUND_SETTINGS); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent2); } }); } catch (Exception e) { Log.e("tag", e.getMessage()); } } else if (options[item].equals(getString(R.string.set_notification))) { File directory_al = new File( Environment.getExternalStorageDirectory() + "/Notifications/"); if (!directory_al.exists()) { directory_al.mkdirs(); } try { InputStream in; OutputStream out; in = new FileInputStream(Selecteditem); out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Notifications/" + SelecteditemTitle); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); // write the output file out.flush(); out.close(); MediaScannerConnection.scanFile(getActivity(), new String[] { Environment.getExternalStorageDirectory() + "/Notifications/" + SelecteditemTitle }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Intent intent2 = new Intent(Settings.ACTION_SOUND_SETTINGS); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent2); } }); } catch (Exception e) { Log.e("tag", e.getMessage()); } } else if (options[item].equals(getString(R.string.set_alarm))) { File directory_al = new File( Environment.getExternalStorageDirectory() + "/Alarms/"); if (!directory_al.exists()) { directory_al.mkdirs(); } try { InputStream in; OutputStream out; in = new FileInputStream(Selecteditem); out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Alarms/" + SelecteditemTitle); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); // write the output file out.flush(); out.close(); MediaScannerConnection.scanFile(getActivity(), new String[] { Environment.getExternalStorageDirectory() + "/Alarms/" + SelecteditemTitle }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Snackbar.make(listView, R.string.set_alarm_suc, Snackbar.LENGTH_LONG).show(); } }); } catch (Exception e) { Log.e("tag", e.getMessage()); } Snackbar.make(listView, getString(R.string.set_alarm_suc), Snackbar.LENGTH_LONG) .show(); } else if (options[item].equals(getString(R.string.play))) { final MediaPlayer mp = MediaPlayer.create(getActivity(), Uri.parse(Selecteditem)); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.play)) .setMessage(SelecteditemMes).setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mp.stop(); dialog.cancel(); } }) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mp.stop(); dialog.cancel(); } }).show(); mp.start(); } else if (options[item].equals(getString(R.string.open))) { Uri uri = Uri.parse(SelecteditemUrl); // missing 'http://' will cause crashed Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } } }).show(); return true; } }); return rootView; }
From source file:com.krayzk9s.imgurholo.services.DownloadService.java
@Override protected void onHandleIntent(Intent intent) { final NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); ids = intent.getParcelableArrayListExtra("ids"); albumName = "/"; downloaded = 0;/*from ww w. j a v a2 s .co m*/ if (ids.size() > 0) { albumName += intent.getStringExtra("albumName") + "/"; File myDirectory = new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName); if (!myDirectory.exists()) { myDirectory.mkdirs(); } } for (int i = 0; i < ids.size(); i++) { try { final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) .split("/")[1]; final String id = ids.get(i).getJSONObject().getString("id"); final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); Log.d("data", ids.get(i).getJSONObject().toString()); Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]); Log.d("id", ids.get(i).getJSONObject().getString("id")); Log.d(ImgurHoloActivity.IMAGE_DATA_LINK, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK)); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(getString(R.string.picture_download)) .setContentText(getString(R.string.download_in_progress)) .setSmallIcon(R.drawable.icon_desaturated); Ion.with(getApplicationContext(), link).progress(new ProgressCallback() { @Override public void onProgress(int i, int i2) { notificationBuilder.setProgress(i2, i, false); } }).write(new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + albumName + id + "." + type)) .setCallback(new FutureCallback<File>() { @Override public void onCompleted(Exception e, File file) { if (file == null) return; downloaded += 1; if (downloaded == ids.size()) { NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder( getApplicationContext()); if (ids.size() == 1) { Intent viewImageIntent = new Intent(Intent.ACTION_VIEW); viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*"); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), shareIntent, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated) .setContentText(String.format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, getString(R.string.share), sharePendingIntent); } else { Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType( Uri.fromFile(new File( android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName)), "image/*"); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), i, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated).setContentText(String .format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent); } notificationManager.cancel(0); notificationManager.cancel(1); notificationManager.notify(1, notificationComplete.build()); } MediaScannerConnection.scanFile(getApplicationContext(), new String[] { android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName + id + "." + type }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path, uri.toString())); } }); } }); notificationManager.notify(0, notificationBuilder.build()); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }
From source file:com.fbbackup.ImageDetailActivity.java
private void setListener() { btn_share.setOnClickListener(new Button.OnClickListener() { @Override//from w w w . j av a 2 s. c om public void onClick(View v) { // TODO Auto-generated method stub // Gets a handle to the clipboard service. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(clipBoardText); PackageManager pm = getPackageManager(); Intent intent = pm.getLaunchIntentForPackage("jp.naver.line.android"); File file = new File(extStorageDirectory + "/DCIM/FBBackup/test.jpg"); Uri outputFileUri = Uri.fromFile(file); String[] path = { extStorageDirectory + "/DCIM/FBBackup/test.jpg" }; // MediaScannerConnection.scanFile(this, path, null, // new MediaScannerConnection.OnScanCompletedListener() { // public void onScanCompleted(String path, Uri uri) { // Log.i("ExternalStorage", "Scanned " + path + ":"); // Log.i("ExternalStorage", "-> uri=" + uri); // } // }); MediaScannerConnection.scanFile(getApplicationContext(), path, null, null); Log.w("RyanWang", outputFileUri.getPath()); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, outputFileUri); intent.setType("image/jpeg"); startActivity(intent); } }); btn_download_photo.setOnClickListener(new ImageButton.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DownloadSinglePicTask download = new DownloadSinglePicTask(); download.setContext(ImageDetailActivity.this); download.setAlbunPhotoUrl(clipBoardText); Log.w("downloadpic", "ImageDetail albumName:" + albumName); download.setPath( extStorageDirectory + "/DCIM/FBBackup/" + name + "/" + Utils.getDirName(albumName) + "/"); download.execute("test"); } }); }
From source file:org.thezero.qrfi.SuperAwesomeCardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView; if (position == 0) { rootView = inflater.inflate(R.layout.fragment_generate, container, false); final CardView cardQr = (CardView) rootView.findViewById(R.id.card_qr); cardQr.setVisibility(View.GONE); String[] items = new String[] { "Open", "WEP", "WPA/WPA2" }; final EditText ssid = (EditText) rootView.findViewById(R.id.edit_ssid); final EditText pass = (EditText) rootView.findViewById(R.id.edit_pass); final Spinner spinner = (Spinner) rootView.findViewById(R.id.wifi_type); ArrayAdapter<String> adapter = new ArrayAdapter<>(c, android.R.layout.simple_spinner_item, items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);/*from w ww. ja v a 2 s. c o m*/ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getSelectedItem().toString().equals("Open")) { rootView.findViewById(R.id.second).setVisibility(View.GONE); } else { rootView.findViewById(R.id.second).setVisibility(View.VISIBLE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); final boolean[] cardHide = { true }; Button delete = (Button) rootView.findViewById(R.id.delete); delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cardHide[0] = true; cardQr.animate().translationY(0).alpha(0.0f).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (cardHide[0]) cardQr.setVisibility(View.GONE); } }); ssid.setText(""); pass.setText(""); spinner.setSelection(0); } }); Button gen = (Button) rootView.findViewById(R.id.generate); gen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // WIFI:S:Pistol;T:WEP;P:pistolawifi2;; if (pass.getText().length() < 8 && !spinner.getSelectedItem().toString().equals("Open")) { Toast.makeText(c, c.getString(R.string.error_pass), Toast.LENGTH_LONG).show(); return; } String ap = "WIFI:S:" + ssid.getText() + ";T:" + spinner.getSelectedItem().toString() + ";P:" + pass.getText() + ";;"; Log.d(TAG, ap); QRCodeWriter writer = new QRCodeWriter(); try { BitMatrix matrix = writer.encode(ap, BarcodeFormat.QR_CODE, 700, 700, null); int height = matrix.getHeight(); int width = matrix.getWidth(); final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bmp.setPixel(x, y, matrix.get(x, y) ? Color.BLACK : Color.WHITE); } } ImageView qr_image = (ImageView) rootView.findViewById(R.id.qrimage); qr_image.setImageBitmap(bmp); cardHide[0] = false; cardQr.setVisibility(View.VISIBLE); cardQr.setAlpha(1.0f); cardQr.animate().translationY(10).alpha(1.0f); Button dialogButton = (Button) rootView.findViewById(R.id.ok); dialogButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { File sdcard = Environment.getExternalStorageDirectory(); FileOutputStream out = null; File check = new File(sdcard, "/wifipv/"); if (!(check.exists())) { boolean resu = check.mkdir(); if (!resu) { return; } } try { File myFile = new File(sdcard, "/wifipv/" + ssid.getText() + ".png"); out = new FileOutputStream(myFile); boolean success = bmp.compress(Bitmap.CompressFormat.PNG, 100, out); if (success) { MediaScannerConnection.scanFile(c, new String[] { myFile.getAbsolutePath() }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Log.d(TAG, "file " + path + " was scanned seccessfully: " + uri); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/png"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent new_intent = Intent.createChooser(shareIntent, c.getText(R.string.send_to)); new_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(new_intent); } }); } else { Toast.makeText(c, c.getString(R.string.error_share), Toast.LENGTH_LONG) .show(); } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (out != null) try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }); } catch (WriterException e) { e.printStackTrace(); } } }); } else { rootView = inflater.inflate(R.layout.fragment_scan, container, false); Button scan = (Button) rootView.findViewById(R.id.scan); scan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent myIntent = new Intent(c, ScanActivity.class); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(myIntent); } }); Button gallery = (Button) rootView.findViewById(R.id.gallery); gallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectFromGallery(); } }); /*final boolean[] tutorialHide = {false}; final CardView tutorial = (CardView)rootView.findViewById(R.id.card_tutorial); tutorial.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(tutorialHide[0]){ tutorialHide[0]=false; Animation anidelta = new ResizeAnimation(tutorial, tutorial.getHeight()); anidelta.setDuration(500); anidelta.setFillAfter(true); tutorial.startAnimation(anidelta); }else{ tutorialHide[0]=true; Animation anidelta = new ResizeAnimation(tutorial, 120); anidelta.setDuration(500); anidelta.setFillAfter(true); tutorial.startAnimation(anidelta); } } });*/ } ViewCompat.setElevation(rootView, 50); return rootView; }
From source file:com.concavenp.artistrymuse.ImageAppCompatActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { switch (requestCode) { case REQUEST_IMAGE_CAPTURE: { // Save off the values generated from the image creation setSpecificImageData(getType()); // If the user has the setting for making the files available outside this app then copy it // Get the sort type that should be used when requesting data from the movie DB SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean scanMedia = prefs.getBoolean(getResources().getString(R.string.media_scanning_key), true); if (scanMedia) { File file = new File(mImagePath); // Tell the media scanner about the new file so that it is immediately available to the user. MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { Log.i("ExternalStorage", "Scanned " + path + ":"); Log.i("ExternalStorage", "-> uri=" + uri); }/*w ww . j a va 2 s . c o m*/ }); } // Load the captured image into the ImageView widget switch (getRectangleOrCircle(getType())) { case IMAGE_SHAPE_CIRCLE: { populateCircularImageView(mImagePath, getSpecificImageView(getType())); break; } case IMAGE_SHAPE_RECTANGLE: default: { populateThumbnailImageView(mImagePath, getSpecificImageView(getType())); break; } } break; } case REQUEST_IMAGE_STORE: { // Use the returned URI by passing it to the content resolver in order to get // access to he file chosen by the user. At this point copy the file locally // so it can be processed in the exact same fashion as the camera retrieved image. // The resulting URI of the user's image pick mSelectedImageUri = data.getData(); // We are about the retrieve files outside of this App's area. To do so, we // must have the right permission. Check to see if we do and then process the // image. If we do not, then request permission by presenting the user a // popup asking for permission. Since, we only bring this up when the user // hits the gallery I've decided to present the obvious reason why this App is // requesting permission. int permissionCheck = ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE); if (permissionCheck == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_PERMISSIONS_READ_EXTERNAL_STORAGE); // Continue processing in the callback associated with permissions (onRequestPermissionsResult) } else { // Copy the file locally and set the thumbnail and Save off the values generated from the image creation new ProcessExternalUriTask().execute(getSpecificImageView(getType())); } break; } } } }
From source file:ar.com.lapotoca.resiliencia.gallery.ui.ImageDetailActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.image_menu, menu); MenuItem shareItem = menu.findItem(R.id.menu_share); shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override/*from w w w . j a v a 2s . co m*/ public boolean onMenuItemClick(MenuItem item) { try { ImageHolder img = Images.image[mPager.getCurrentItem()]; if (img == null) { return false; } AnalyticsHelper.getInstance().sendImageShareEvent(img.getUrl()); Uri bmpUri; if (img.isLocal()) { bmpUri = Uri.parse("content://" + AssetProvider.CONTENT_URI + "/" + img.getUrl()); } else { ImageView iv = (ImageView) findViewById(R.id.picImageView); bmpUri = getLocalBitmapUri(iv); } if (bmpUri != null) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_item))); AnalyticsHelper.getInstance().sendImageShareCompleted(); return true; } else { AnalyticsHelper.getInstance().sendImageShareCanceled(); return false; } } catch (Exception e) { AnalyticsHelper.getInstance().sendImageShareFailed(e.getMessage()); return false; } } }); MenuItem downloadItem = menu.findItem(R.id.download_asset); downloadItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Context context = ImageDetailActivity.this; String appDirectoryName = context.getString(R.string.app_name); File imageRoot = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); ImageHolder img = Images.image[mPager.getCurrentItem()]; if (img == null) { return false; } AssetManager assetManager = context.getAssets(); try { InputStream is = assetManager.open(img.getUrl()); String fileName = img.getUrl().split("/")[1]; imageRoot.mkdirs(); File image = new File(imageRoot, fileName); byte[] buffer = new byte[BUFFER_LENGHT]; FileOutputStream fos = new FileOutputStream(image); int read = 0; while ((read = is.read(buffer, 0, 1024)) >= 0) { fos.write(buffer, 0, read); } fos.flush(); fos.close(); is.close(); String[] paths = { image.getAbsolutePath() }; MediaScannerConnection.scanFile(context, paths, null, null); NotificationHelper.showNotification(context, context.getString(R.string.download_image_succesfull)); AnalyticsHelper.getInstance().sendDownloadImage(fileName); } catch (Exception e) { NotificationHelper.showNotification(context, context.getString(R.string.download_no_permissions)); AnalyticsHelper.getInstance().sendImageDownloadFailed(e.getMessage()); } return true; } }); return true; }
From source file:mobisocial.musubi.objects.PictureObj.java
@Override public boolean processObject(Context context, MFeed feed, MIdentity sender, MObject object) { DbObj obj = App.getMusubi(context).objForId(object.id_); File thumbFile = CorralDownloadClient.localFileForContent(obj, true); try {/*ww w . jav a2 s. c om*/ FileOutputStream fout = new FileOutputStream(thumbFile); ByteArrayInputStream fin = new ByteArrayInputStream(object.raw_); IOUtils.copy(fin, fout); String[] paths = new String[] { thumbFile.getAbsolutePath() }; MediaScannerConnection.scanFile(context, paths, null, null); } catch (IOException e) { Log.e(TAG, "Error saving thumbnail", e); thumbFile.delete(); } return true; }
From source file:com.ls.sip.CameraFragment.java
@SuppressWarnings({ "unused", "ConstantConditions" }) public void onEventMainThread(CameraEngine.VideoTakenEvent event) { if (event.exception == null) { if (getArguments().getBoolean(ARG_UPDATE_MEDIA_STORE, false)) { final Context app = getActivity().getApplicationContext(); Uri output = getArguments().getParcelable(ARG_OUTPUT); final String path = output.getPath(); new Thread() { @Override//from w w w . ja v a2 s. c o m public void run() { SystemClock.sleep(2000); MediaScannerConnection.scanFile(app, new String[] { path }, new String[] { "video/mp4" }, null); } }.start(); } isVideoRecording = false; btnTakePicture.setImageResource(R.drawable.cwac_cam2_ic_videocam); } else { getActivity().finish(); } }
From source file:com.silentcircle.contacts.detail.PhotoSelectionHandler.java
/** * Sends a newly acquired photo to Gallery for cropping *///from ww w. j a v a 2 s .c o m private void doCropPhoto(String fileName) { try { // Obtain the absolute paths for the newly-taken photo, and the destination // for the soon-to-be-cropped photo. final String newPath = ContactPhotoUtils.pathForNewCameraPhoto(fileName); final String croppedPath = ContactPhotoUtils.pathForCroppedPhoto(mContext, fileName); // Add the image to the media store MediaScannerConnection.scanFile(mContext, new String[] { newPath }, new String[] { null }, null); // Launch gallery to crop the photo final Intent intent = getCropImageIntent(newPath, croppedPath); startPhotoActivity(intent, REQUEST_CODE_PHOTO_PICKED_WITH_DATA, fileName); } catch (Exception e) { Log.e(TAG, "Cannot crop image", e); Toast.makeText(mContext, R.string.photoPickerNotFoundText, Toast.LENGTH_LONG).show(); } }
From source file:com.amaze.filemanager.utils.Futils.java
public void scanFile(String path, Context c) { System.out.println(path + " " + Build.VERSION.SDK_INT); if (Build.VERSION.SDK_INT >= 19) { MediaScannerConnection.scanFile(c, new String[] { path }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override// w w w .java 2 s . c o m public void onScanCompleted(String path, Uri uri) { } }); } else { Uri contentUri = Uri.fromFile(new File(path)); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri); c.sendBroadcast(mediaScanIntent); } }