我可以从网上下载图像并将它们保存到Cache,现在我需要将它们的路径存储在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)";