遍历删除.apk

deleteFile(new File("/storage/emulated/0/"));

public void deleteFile(File file){
【遍历删除.apk】File[] allFile = file.listFiles();
Log.w(TAG, "allFile" + allFile);
Log.w(TAG, "allFile" + WXS);
for(File f : allFile){
try{
int MAX=5;
for (int i=0; i if (f.getName().endsWith(".apk")){

Log.w(TAG, "f.getName()" +f.getName());
Log.w(TAG, "f.getName()" + f.getName().endsWith(".apk"));
boolean f1 =f.getAbsoluteFile().delete();
Log.w(TAG, "f1" + f1);
Thread.sleep(40);
Log.w(TAG, "f.delete()" + WXS);
Log.w(TAG, "f.delete()" + f.delete());
}
else{
break;
}
}
}catch (Exception e)
{
//TODO Auto-generated catch block
e.printStackTrace();
}
}
}
删除v

第二种方法
public void deleteFile(){
try{
File file = new File(mPackageURI.getPath());
Log.w(TAG, "file" +file);
//int MAX =5;
//for (int i =0; i if (file.exists()){
Log.w(TAG, "file.exists()" + file.exists());
boolean IE = file.getAbsoluteFile().delete();
Thread.sleep(30);
Log.w(TAG, "IE" + IE );
}
//else{
// break;
//}
//}
}
catch (Exception e){
//TODO Auto-generated catch block
e.printStackTrace();
}
}
第三种方法

public void deleteFile(){
try{
File file = new File(mPackageURI.getPath());
Log.w(TAG, "file" +file);
//int MAX =5;
//for (int i =0; i if (file.exists()){
Log.w(TAG, "file.exists()" + file.exists());
Thread.sleep(30);
boolean IE = file.getAbsoluteFile().delete();
Thread.sleep(30);
Log.w(TAG, "IE" + IE );
}
//else{
// break;
//}
//}
}
catch (Exception e){
//TODO Auto-generated catch block
e.printStackTrace();
}
}
注意函数的位置

public void onClick(View v) {
if(v == mDoneButton) {
if (mAppInfo.packageName != null) {
Log.i(TAG, "Finished installing "+mAppInfo.packageName);
Log.w(TAG, "onClick"+ WXS);
}
//;
clearCachedApkIfNeededAndFinish();
//deleteFile(new File("/storage/emulated/0/"));
deleteFile();
} else if(v == mLaunchButton) {
try {
startActivity(mLaunchIntent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Could not start activity", e);
}
//deleteFile(new File("/storage/emulated/0/"));
clearCachedApkIfNeededAndFinish();
}
}
try catch 函数定义
try {//
Thread.sleep(15000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

    推荐阅读