mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-03 21:21:12 +08:00
Fix PCAP file deletion on some Android versions
This commit is contained in:
parent
4c0ce35085
commit
20ef821b76
@ -715,13 +715,27 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
}
|
||||
|
||||
private void deletePcapFile(Uri pcapUri) {
|
||||
Log.d(TAG, "Deleting PCAP file" + pcapUri.getPath());
|
||||
boolean deleted = false;
|
||||
|
||||
try {
|
||||
deleted = (getContentResolver().delete(pcapUri, null, null) == 1);
|
||||
} catch (UnsupportedOperationException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
// The getContentResolver().delete in some Android versions does not work, try to delete
|
||||
// using file path first
|
||||
String fpath = Utils.uriToFilePath(this, pcapUri);
|
||||
if(fpath != null) {
|
||||
Log.d(TAG, "deletePcapFile: path=" + fpath);
|
||||
|
||||
try {
|
||||
deleted = new File(fpath).delete();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "deletePcapFile: uri=" + pcapUri);
|
||||
|
||||
try {
|
||||
deleted = (getContentResolver().delete(pcapUri, null, null) == 1);
|
||||
} catch (UnsupportedOperationException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(!deleted)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user