In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to store pictures in Android to the specified path", the content of the explanation in the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to store pictures in Android to the specified path" bar!
1. First of all, long press save: this can refer to the network, nothing more than their own splicing of a file path. Note: IO streams can only help create files, but not directories (paths).
/ / stitching a path first: make a folder String filePath = Environment.getExternalStorageDirectory () + savePath; File localFile = new File (filePath) on the memory card / or mobile memory; if (! localFile.exists ()) {localFile.mkdir ();}
two。 Boot the specific file name and path:
/ / stitching the file path and name File finalImageFile = new File (localFile, System.currentTimeMillis () + ".jpg"); if (finalImageFile.exists ()) {finalImageFile.delete ();} try {finalImageFile.createNewFile ();} catch (IOException e) {e.printStackTrace ();}
3. Reading of files:
FileOutputStream fos = null; try {fos = new FileOutputStream (finalImageFile);} catch (FileNotFoundException e) {e.printStackTrace ();} if (bitmap = = null) {Toast.makeText (this, "picture does not exist", 0). Show (); return;} bitmap.compress (Bitmap.CompressFormat.JPEG, 100, fos); try {fos.flush (); fos.close () Toast.makeText (this, "picture saved in:" + finalImageFile.getAbsolutePath (), 0). Show ();} catch (IOException e) {e.printStackTrace ();}
4. For the picture, we also want to store it behind the fixed path, and we want to be able to view the picture in the album. It is possible to use a broadcast to tell the album that there are picture updates.
/ / broadcast to tell the album that there are pictures that need to be updated, so that you can see the saved pictures under the album Intent intent = new Intent (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri uri = Uri.fromFile (finalImageFile); intent.setData (uri); sendBroadcast (intent)
Through the above steps: we can view the stored pictures in the folder and photo album of the specified path.
The effect is as follows:
5. In addition, although toast prompts the user to store the path, it will not be found. In fact, when testing with a real machine (without an SD card), the picture is stored in the phone's own memory = "ememed =" where the picture is.
6. Storing SD cards, this kind of operation often requires permission. So, don't forget to configure permissions in AndroidManifest:
Thank you for your reading, the above is the content of "how to store pictures in Android to the specified path". After the study of this article, I believe you have a deeper understanding of how to store pictures in Android to the specified path, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.