图库搜索不到如何删除sd卡里的东西图片

当前访客身份:游客 [
:/tgyf/p/4649319.html...
:我知道了。
:很好 很好 好文章! 谢谢!
:不错不错
:引用来自“DarcyYe”的评论 引用来自“海风心情”...
:引用来自“海风心情”的评论看到你们3.0版本了,...
今日访问:13
昨日访问:69
本周访问:181
本月访问:814
所有访问:20317
Android--保存图片在SD卡中,在相册中(Gallery)能马上找到
发表于2年前( 19:00)&&
阅读(2031)&|&评论()
0人收藏此文章,
老大要求把图片保存在本地,然后一打开相册(Gallery)就能看到.
这个问题纠结了挺久的..
一般情况下直接保存在SD卡某个目录下面,是不能马上就在Gallery中看到的,要过段时间才能看到.
具体原因还没深究,以后再加吧..
先把问题解决了再说:
保存图片后,加个广播:
* 让Gallery上能马上看到该图片
private static void scanPhoto(Context ctx, String imgFileName) {
Intent mediaScanIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File file = new File(imgFileName);
Uri contentUri = Uri.fromFile(file);
mediaScanIntent.setData(contentUri);
ctx.sendBroadcast(mediaScanIntent);
&OK...希望能能帮到有需要的朋友.
我是在这里找到的:
更多开发者职位上
1)">1)">1" ng-class="{current:{{currentPage==page}}}" ng-repeat="page in pages"><li class='page' ng-if="(endIndex<li class='page next' ng-if="(currentPage安卓手机图库搜不到图片,内存卡里面有_百度知道
安卓手机图库搜不到图片,内存卡里面有
视频也是一样,怎么解决?
我有更好的答案
同样的,内存卡损坏了,修复一下就行了。右键可移动磁盘,属性,工具,检查整理,全部勾上,然后解决。
其他类似问题
4人觉得有用
为您推荐:
您可能关注的推广回答者:
安卓手机的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁图片在sd卡里,在文件管理器里可以找到图,打的开,但是图库打开一张..._百度知道
图片在sd卡里,在文件管理器里可以找到图,打的开,但是图库打开一张...
图片在sd卡里,在文件管理器里可以找到图,打的开,但是图库打开一张我那里面的图都没有,怎么回事啊????
原来可以正常打开的,我没有下新图片
我有更好的答案
有可能你在sd卡里没找到
把sd卡的图片考到电脑看能不能打开,要是能打开,可能是存储在SD卡下读取有问题;要是也打不开,就是你SD卡里图片有问题。
查询SD卞的图片
其他类似问题
为您推荐:
文件管理器的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁1.java代码,下载图片的主程序
先实现显示图片,然后点击下载图片按钮,执行下载功能。
从网络上取得的图片,生成Bitmap时有两种方法,一种是先转换为byte[],再生成bitmap;一种是直接用InputStream生成bitmap。
(1)ICS4.0及更高版本中的实现
4.0中不允许在主线程,即UI线程中操作网络,所以必须新开一个线程,在子线程中执行网络连接;然后在主线程中显示图片。
public class IcsTestActivity extends Activity {
private final static String TAG = "IcsTestActivity";
private final static String ALBUM_PATH
= Environment.getExternalStorageDirectory() + "/download_test/";
private ImageView mImageV
private Button mBtnS
private ProgressDialog mSaveDialog = null;
private Bitmap mB
private String mFileN
private String mSaveM
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView = (ImageView)findViewById(R.id.imgSource);
mBtnSave = (Button)findViewById(R.id.btnSave);
new Thread(connectNet).start();
// 下载图片
mBtnSave.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
mSaveDialog = ProgressDialog.show(IcsTestActivity.this, "保存图片", "图片正在保存中,请稍等...", true);
new Thread(saveFileRunnable).start();
* Get image from newwork
* @param path The path of image
* @return byte[]
* @throws Exception
public byte[] getImage(String path) throws Exception{
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setRequestMethod("GET");
InputStream inStream = conn.getInputStream();
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
return readStream(inStream);
return null;
* Get image from newwork
* @param path The path of image
* @return InputStream
* @throws Exception
public InputStream getImageStream(String path) throws Exception{
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setRequestMethod("GET");
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
return conn.getInputStream();
return null;
* Get data from stream
* @param inStream
* @return byte[]
* @throws Exception
public static byte[] readStream(InputStream inStream) throws Exception{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len=inStream.read(buffer)) != -1){
outStream.write(buffer, 0, len);
outStream.close();
inStream.close();
return outStream.toByteArray();
* 保存文件
* @param bm
* @param fileName
* @throws IOException
public void saveFile(Bitmap bm, String fileName) throws IOException {
File dirFile = new File(ALBUM_PATH);
if(!dirFile.exists()){
dirFile.mkdir();
File myCaptureFile = new File(ALBUM_PATH + fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
bm.pressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
private Runnable saveFileRunnable = new Runnable(){
public void run() {
saveFile(mBitmap, mFileName);
mSaveMessage = "图片保存成功!";
} catch (IOException e) {
mSaveMessage = "图片保存失败!";
e.printStackTrace();
messageHandler.sendMessage(messageHandler.obtainMessage());
private Handler messageHandler = new Handler() {
public void handleMessage(Message msg) {
mSaveDialog.dismiss();
Log.d(TAG, mSaveMessage);
Toast.makeText(IcsTestActivity.this, mSaveMessage, Toast.LENGTH_SHORT).show();
* 连接网络
* 由于在4.0中不允许在主线程中访问网络,所以需要在子线程中访问
private Runnable connectNet = new Runnable(){
public void run() {
String filePath = "http://img.my.csdn.net/uploads//_4579.jpg";
mFileName = "test.jpg";
//以下是取得图片的两种方法
//////////////// 方法1:取得的是byte数组, 从byte数组生成bitmap
byte[] data = getImage(filePath);
if(data!=null){
mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);// bitmap
Toast.makeText(IcsTestActivity.this, "Image error!", 1).show();
////////////////////////////////////////////////////////
//******** 方法2:取得的是InputStream,直接从InputStream生成bitmap ***********/
mBitmap = BitmapFactory.decodeStream(getImageStream(filePath));
//********************************************************************/
// 发送消息,通知handler在主线程中更新UI
connectHanlder.sendEmptyMessage(0);
Log.d(TAG, "set image ...");
} catch (Exception e) {
Toast.makeText(IcsTestActivity.this,"无法链接网络!", 1).show();
e.printStackTrace();
private Handler connectHanlder = new Handler() {
public void handleMessage(Message msg) {
Log.d(TAG, "display image");
// 更新UI,显示图片
if (mBitmap != null) {
mImageView.setImageBitmap(mBitmap);// display image
(2)2.3以及以下版本可以在主线程中操作网络连接,但最好不要这样做,因为连接网络是阻塞的,如果5秒钟还没有连接上,就会引起ANR。
public class AndroidTest2_3_3 extends Activity {
private final static String TAG = "AndroidTest2_3_3";
private final static String ALBUM_PATH
= Environment.getExternalStorageDirectory() + "/download_test/";
private ImageView imageV
private Button btnS
private ProgressDialog myDialog = null;
private String fileN
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView)findViewById(R.id.imgSource);
btnSave = (Button)findViewById(R.id.btnSave);
String filePath = "http://hi.csdn.net/attachment//u.jpg";
fileName = "test.jpg";
//////////////// 取得的是byte数组, 从byte数组生成bitmap
byte[] data = getImage(filePath);
if(data!=null){
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);// bitmap
imageView.setImageBitmap(bitmap);// display image
Toast.makeText(AndroidTest2_3_3.this, "Image error!", 1).show();
////////////////////////////////////////////////////////
//******** 取得的是InputStream,直接从InputStream生成bitmap ***********/
bitmap = BitmapFactory.decodeStream(getImageStream(filePath));
if (bitmap != null) {
imageView.setImageBitmap(bitmap);// display image
//********************************************************************/
Log.d(TAG, "set image ...");
} catch (Exception e) {
Toast.makeText(AndroidTest2_3_3.this,"Newwork error!", 1).show();
e.printStackTrace();
// 下载图片
btnSave.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
myDialog = ProgressDialog.show(AndroidTest2_3_3.this, "保存图片", "图片正在保存中,请稍等...", true);
new Thread(saveFileRunnable).start();
* Get image from newwork
* @param path The path of image
* @return byte[]
* @throws Exception
public byte[] getImage(String path) throws Exception{
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setRequestMethod("GET");
InputStream inStream = conn.getInputStream();
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
return readStream(inStream);
return null;
* Get image from newwork
* @param path The path of image
* @return InputStream
* @throws Exception
public InputStream getImageStream(String path) throws Exception{
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setRequestMethod("GET");
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
return conn.getInputStream();
return null;
* Get data from stream
* @param inStream
* @return byte[]
* @throws Exception
public static byte[] readStream(InputStream inStream) throws Exception{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len=inStream.read(buffer)) != -1){
outStream.write(buffer, 0, len);
outStream.close();
inStream.close();
return outStream.toByteArray();
* 保存文件
* @param bm
* @param fileName
* @throws IOException
public void saveFile(Bitmap bm, String fileName) throws IOException {
File dirFile = new File(ALBUM_PATH);
if(!dirFile.exists()){
dirFile.mkdir();
File myCaptureFile = new File(ALBUM_PATH + fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
bm.pressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
private Runnable saveFileRunnable = new Runnable(){
public void run() {
saveFile(bitmap, fileName);
message = "图片保存成功!";
} catch (IOException e) {
message = "图片保存失败!";
e.printStackTrace();
messageHandler.sendMessage(messageHandler.obtainMessage());
private Handler messageHandler = new Handler() {
public void handleMessage(Message msg) {
myDialog.dismiss();
Log.d(TAG, message);
Toast.makeText(AndroidTest2_3_3.this, message, Toast.LENGTH_SHORT).show();
下载进度条的可以参考我的另外一个帖子:
2.main.xml文件,只有一个button和一个ImageView
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="保存图片"
&ImageView
android:id="@+id/imgSource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
&/LinearLayout&
3.在mainfest文件中增加互联网权限和写sd卡的权限
&uses-permission android:name="android.permission.INTERNET" /&
&uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&
&uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/&
4.预览图:
阅读(...) 评论()}

我要回帖

更多关于 怎样删除sd卡里的东西 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信