Android Image Deposit System Album update Display instance detailed
In the process of developing Android, we could not avoid the possibility of making a custom album or creating a local folder to store the images we need. Take a photo album, for example, we create a test folder, after a photo is stored in the specified test folder, and then displayed in the album, like the effect. Can be displayed immediately after the shot. However, in the actual development process after we save a picture and not immediately update the display of this image, we need to restart the phone to be displayed in the System album.
Here's a way to insert a system gallery:
MediaStore.Images.Media.insertImage (Getcontentresolver (), Mbitmap, "", "" ");
This method allows you to insert a picture into the system gallery. However, after inserting it does not appear immediately and requires sending a broadcast: Sendbroadcast (New Intent (intent.action_media_mounted, Uri.parse ("file://" + Environment.getexternalstoragedirectory ())));
To notify the system to scan the entire SD card, if the more things in the SD will scan the longer, and the scan we can not access the SD card, so the implementation of this way is not friendly to the user.
Here we can use the system Api:mediascannerconnection to our method for scanning updates:
-
-
- @Override
- protected void onCreate (Bundle savedinstancestate) {
- super.o Ncreate (savedinstancestate);
-
- mhandler.sendemptymessagedelayed (1, +);
-
- mconnection =new mediascannerconnection (mcontext,this);
- }
-
- @Override
- public void onmediascannerconnected () {
- mconnection.scanfile ("/s Dcard/image.jpg "," image/jpeg ");
- }
-
- @Override
- public void onscancompleted (String s, Uri Uri) {
- log.v ("Huan", "s Can completed ");
- Mconnection.disconnect ();
- }
-
-
http://www.kmjdad.com/
http://www.jnsjzyy.com/
http://www.czhkwl.com/
http://www.express-o2o.com/
http://www.gzjindao.com/
http://www.chumingchuanmeiyishu.com/
http://www.thcxb.com/
http://www.xingguangkeji.com/
http://www.gdrhsy.com/
http://www.clhuiji.com/
http://www.nxjianye.com/
http://www.tjmingsheng.com/
http://www.gangguan022.com/
http://www.zyjbp.com/
http://www.qianhangmy.com/
http://www.tzminbell.com/
Copy Code
But this method I found in the process of the problem is: the incoming context will be mediascannerconnection has been held, resulting in oom. So you need to be aware of the activity when you use it.
We can also broadcast by specifying a path so that you can avoid scanning the entire SD card:
- Sendbroadcast (New Intent (intent.action_media_mounted, Uri.parse ("file://" + Environment.getexternalstoragedirectory () + Picpath));
Copy Code
Photo Update tips and precautions to share to everyone, hope to help you.
Android Image Deposit System Album update Display instance detailed