Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
File Recovery RecycleBin
Commits
ca69e2d5
Commit
ca69e2d5
authored
Jul 22, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
....MediaContentObserver uri方式删除文件
parent
dfd8363d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
19 deletions
+27
-19
MeidaContentObserver.kt
...eryrecyclebin/activity/recyclebin/MeidaContentObserver.kt
+21
-12
MyFileObserver.kt
...erecoveryrecyclebin/activity/recyclebin/MyFileObserver.kt
+3
-6
RecycleBinBean.kt
...va/com/base/filerecoveryrecyclebin/bean/RecycleBinBean.kt
+3
-0
StayNotificationService.kt
...filerecoveryrecyclebin/service/StayNotificationService.kt
+0
-1
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/activity/recyclebin/MeidaContentObserver.kt
View file @
ca69e2d5
...
...
@@ -5,7 +5,6 @@ import android.content.Context
import
android.database.ContentObserver
import
android.database.Cursor
import
android.net.Uri
import
android.os.Handler
import
android.provider.MediaStore
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.getRecycleBinDir
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean
...
...
@@ -35,7 +34,7 @@ class MediaContentObserver(val context: Context) : ContentObserver(null) {
@SuppressLint
(
"Range"
)
private
fun
queryNewMediaFiles
(
uri
:
Uri
)
{
private
fun
queryNewMediaFiles
(
uri
:
Uri
)
=
Thread
{
// 查询新添加的媒体文件
val
projection
=
arrayOf
(
MediaStore
.
MediaColumns
.
DISPLAY_NAME
,
...
...
@@ -46,23 +45,33 @@ class MediaContentObserver(val context: Context) : ContentObserver(null) {
val
cursor
:
Cursor
?
=
context
.
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
if
(
cursor
!=
null
)
{
LogEx
.
logDebug
(
TAG
,
"cursor=$cursor"
)
try
{
while
(
cursor
.
moveToNext
())
{
val
name
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DISPLAY_NAME
))
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DATA
))
val
mimeType
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
MIME_TYPE
))
val
size
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
SIZE
))
// 处理新文件路径
backupRecycleBinFile
(
name
,
path
,
mimeType
)
if
(
cursor
.
count
>
0
)
{
while
(
cursor
.
moveToNext
())
{
val
name
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DISPLAY_NAME
))
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DATA
))
val
mimeType
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
MIME_TYPE
))
val
size
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
SIZE
))
LogEx
.
logDebug
(
TAG
,
"path=$path"
)
// 处理新文件路径
backupRecycleBinFile
(
name
,
path
,
mimeType
)
}
}
else
{
LogEx
.
logDebug
(
TAG
,
"count=0 deleted file uri"
)
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
LogEx
.
logDebug
(
TAG
,
"Exception=$e"
)
}
finally
{
cursor
.
close
()
}
}
else
{
LogEx
.
logDebug
(
TAG
,
"cursor=$cursor"
)
}
}
}
.
start
()
private
fun
backupRecycleBinFile
(
name
:
String
,
path
:
String
,
mimeType
:
String
)
{
val
src
=
File
(
path
)
...
...
@@ -79,7 +88,7 @@ class MediaContentObserver(val context: Context) : ContentObserver(null) {
if
(
src
.
length
()
>
0L
)
{
val
recycleBinFile
=
File
(
getRecycleBinDir
(),
".$name"
)
src
.
copyTo
(
recycleBinFile
,
true
)
val
binBean
=
RecycleBinBean
(
src
.
path
,
0
,
src
.
length
(),
mimeType
)
val
binBean
=
RecycleBinBean
(
src
.
path
,
deleteTime
=
0
,
size
=
src
.
length
(),
mimeType
=
mimeType
)
val
binFile
=
File
(
recycleBinDir
,
".$name.bin"
)
binFile
.
createNewFile
()
binFile
.
writeText
(
Gson
().
toJson
(
binBean
))
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/activity/recyclebin/MyFileObserver.kt
View file @
ca69e2d5
package
com.base.filerecoveryrecyclebin.activity.recyclebin
import
android.annotation.SuppressLint
import
android.os.Build
import
android.os.FileObserver
import
android.os.Handler
import
androidx.annotation.RequiresApi
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.findRecycleBinFile
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.findRecycleBinJsonFile
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean
...
...
@@ -12,7 +9,7 @@ import com.base.filerecoveryrecyclebin.utils.LogEx
import
com.google.gson.Gson
import
java.io.File
@
RequiresApi
(
Build
.
VERSION_CODES
.
Q
)
@
SuppressLint
(
"NewApi"
)
class
MyFileObserver
(
files
:
List
<
File
>)
:
FileObserver
(
files
,
ALL_EVENTS
)
{
private
val
TAG
=
"MyFileObserver"
...
...
@@ -56,7 +53,7 @@ class MyFileObserver(files: List<File>) : FileObserver(files, ALL_EVENTS) {
}
private
fun
recordRecycleBinFile
(
namePath
:
String
)
{
private
fun
recordRecycleBinFile
(
namePath
:
String
)
=
Thread
{
val
recycleBinFile
=
findRecycleBinFile
(
namePath
)
...
...
@@ -78,6 +75,6 @@ class MyFileObserver(files: List<File>) : FileObserver(files, ALL_EVENTS) {
}
}
}
}
.
start
()
}
\ No newline at end of file
app/src/main/java/com/base/filerecoveryrecyclebin/bean/RecycleBinBean.kt
View file @
ca69e2d5
package
com.base.filerecoveryrecyclebin.bean
import
android.net.Uri
data class
RecycleBinBean
(
val
path
:
String
=
""
,
val
uri
:
Uri
=
Uri
.
EMPTY
,
var
deleteTime
:
Long
=
0
,
val
size
:
Long
=
0
,
val
mimeType
:
String
=
""
,
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/service/StayNotificationService.kt
View file @
ca69e2d5
...
...
@@ -12,7 +12,6 @@ import android.graphics.BitmapFactory
import
android.graphics.drawable.Icon
import
android.os.Build
import
android.os.Environment
import
android.os.Handler
import
android.os.IBinder
import
android.provider.MediaStore
import
android.widget.RemoteViews
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment