本文整理匯總了Java中org.fdroid.fdroid.data.SanitizedFile.delete方法的典型用法代碼示例。如果您正苦於以下問題:Java SanitizedFile.delete方法的具體用法?Java SanitizedFile.delete怎麽用?Java SanitizedFile.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.fdroid.fdroid.data.SanitizedFile
的用法示例。
在下文中一共展示了SanitizedFile.delete方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyApkToFiles
import org.fdroid.fdroid.data.SanitizedFile; //導入方法依賴的package包/類
/**
* Copy an APK from {@param apkFile} to our internal files directory for 20 minutes.
*
* @param verifyHash If the file was just downloaded, then you should mark this as true and
* request the file to be verified once it has finished copying. Otherwise,
* if the app was installed from part of the system where it can't be tampered
* with (e.g. installed apks on disk) then
*/
private static SanitizedFile copyApkToFiles(Context context, File apkFile, String destinationName,
boolean verifyHash, String hash, String hashType)
throws IOException {
SanitizedFile sanitizedApkFile = new SanitizedFile(context.getFilesDir(), destinationName);
// Don't think this is necessary, but the docs for FileUtils#copyFile() are not clear
// on whether it overwrites destination files (pretty confident it does, as per the docs
// in FileUtils#copyFileToDirectory() - which delegates to copyFile()).
if (sanitizedApkFile.exists()) {
sanitizedApkFile.delete();
}
FileUtils.copyFile(apkFile, sanitizedApkFile);
// verify copied file's hash with expected hash from Apk class
if (verifyHash && !Hasher.isFileMatchingHash(sanitizedApkFile, hash, hashType)) {
FileUtils.deleteQuietly(apkFile);
throw new IOException(apkFile + " failed to verify!");
}
// 20 minutes the start of the install process, delete the file
final File apkToDelete = sanitizedApkFile;
new Thread() {
@Override
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST);
try {
Thread.sleep(1200000);
} catch (InterruptedException ignored) {
} finally {
FileUtils.deleteQuietly(apkToDelete);
}
}
}.start();
return sanitizedApkFile;
}