1

我可以从网上下载图像并将它们保存到缓存中,现在我需要将它们的路径存储在 SQLite 数据库中。任何帮助请!提前谢谢。下面是我在http://www.androidhive.info帮助下的代码片段 :

//Saving  Cached  Images  to  File  E_Meges
package com.img.see;

import java.io.File;

import android.content.Context;

public class Cache2Fyle {

     private File kacheDirectory;

        public Cache2Fyle(Context context){

            //Find the dir to save cached images
            if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))

  kacheDirectory= new File(android.os.Environment.getExternalStorageDirectory(),"E_Megez");

 else
                kacheDirectory=context.getCacheDir();

 if(!kacheDirectory.exists())

 kacheDirectory.mkdirs();

 }

 public File getFile(String url){

  String filename=String.valueOf(url.hashCode());

            File fyl = new File(kacheDirectory, filename);

            return fyl;

        }

        public void clear(){

  File[] files=kacheDirectory.listFiles();

            if(files==null)

                return;

            for(File fyl:files)

                fyl.delete();
        }

}

//要显示的主类

package com.img.see;

import android.app.Activity;

import android.os.Bundle;

import android.widget.ImageView;


public class SampleCaching extends Activity {

  @Override

   public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

     setContentView(R.layout.main);


          int loader = R.drawable.loader;


        // Imageview to show

  ImageView image = (ImageView) findViewById(R.id.image);


        // Url for  Image  from  web        
   String image_url = "http://muk.akatsuki.info/photos/Image1.jpg";

  ImageLoader imgLoader = new ImageLoader(getApplicationContext());


     imgLoader.DisplayImage(image_url, loader, image);

 }
}

//数据库表

    String img = "CREATE TABLE photos ( _ID INTEGER PRIMARY KEY,Name TEXT, Image TEXT)";
4

0 回答 0