80,490
社区成员
发帖
与我相关
我的任务
分享ublic class AntiVirusDao {
private static String DB_PATH = "";
private static String DB_NAME = "antivirus.db";
public static String checkVirus(String md5,Context context){
String desc = null;
/**打开病毒MD5数据库*/
SQLiteDatabase db = SQLiteDatabase.openDatabase
(DB_PATH = context.getApplicationInfo().dataDir + "/"+DB_NAME,null,SQLiteDatabase.OPEN_READWRITE);
Cursor cursor = db.rawQuery("select desc from datable where md5=?",new String[]{md5});
if(cursor.moveToNext()){
desc = cursor.getString(0);
}
cursor.close();
db.close();
return desc;
}new Thread(){
public void run(){
Message msg = Message.obtain();
msg.what = SCAN_BEGIN;
myHandler.sendMessage(msg);//sengEmptyMessage只能存放整形数据,sendMessage可以存放其他类型
List<PackageInfo> installedPackage = pm.getInstalledPackages(0);
total = installedPackage.size();
for(PackageInfo info : installedPackage){
if(!flag){
isStop = true;
return;
}
String apkpath = info.applicationInfo.sourceDir;
String md5info = MD5Utils.getFileMD5(apkpath);
// context = getApplicationContext();
String result = AntiVirusDao.checkVirus(md5info,mcontext);
msg = Message.obtain();
msg.what = SCANNING;
ScanAppInfo scanAppInfo = new ScanAppInfo();
if(result==null){
scanAppInfo.description = "您的手机安全";
scanAppInfo.isVirus = false;
}else {
scanAppInfo.description = result;
scanAppInfo.isVirus = true;
}
process++;
scanAppInfo.packageName = info.packageName;
scanAppInfo.appName = info.applicationInfo.loadLabel(pm).toString();
msg.obj = scanAppInfo;
msg.arg1 = process;
myHandler.sendMessage(msg);
try{
Thread.sleep(300);
}catch (InterruptedException e){
e.printStackTrace();
}
}
msg = Message.obtain();
msg.what = SCAN_FINISH;
myHandler.sendMessage(msg);
};
}.start();
}




private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
拷贝完毕以后就可以用SQLiteDatabase去读取DB_PATH + DB_NAME的数据库了。[/quote]
谢谢您的回答,对我非常有帮助。请问这个DB_PATH是我随意指定?我自己声明一个路径?
比如我自己定义 String DB_PATH = “/data/data/com.example.administrator.security/databases/”
然后去读 DB_PATH+“antivirus.db”
这样对么?新手,望不吝赐教
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
拷贝完毕以后就可以用SQLiteDatabase去读取DB_PATH + DB_NAME的数据库了。