Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
H
HookNotify
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
steve
HookNotify
Commits
7a63e917
Commit
7a63e917
authored
Feb 24, 2022
by
steve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改-先将开发中的部份注解掉
parent
07480384
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
128 deletions
+128
-128
LogSaveUnit.kt
app/src/main/java/com/go/hookNotify/units/LogSaveUnit.kt
+128
-128
No files found.
app/src/main/java/com/go/hookNotify/units/LogSaveUnit.kt
View file @
7a63e917
...
@@ -35,134 +35,134 @@ object LogSaveUnit {
...
@@ -35,134 +35,134 @@ object LogSaveUnit {
/**
//
/**
* android 版本 0..28(小於29)
//
* android 版本 0..28(小於29)
* 檢查文件是否存在
//
* 檢查文件是否存在
*/
//
*/
private
fun
checkFileLTAndroidQ
(
context
:
Context
,
saveFileName
:
String
):
String
{
//
private fun checkFileLTAndroidQ(context: Context, saveFileName: String): String {
var
getSaveContent
=
""
//
var getSaveContent = ""
val
destFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_PICTURES
),
saveFileName
)
//
val destFile = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), saveFileName)
val
uri
:
Uri
?
//
val uri: Uri?
if
(
destFile
.
exists
())
uri
=
Uri
.
parse
(
"file://"
+
destFile
.
absoluteFile
)
else
return
""
//
if (destFile.exists()) uri = Uri.parse("file://" + destFile.absoluteFile) else return ""
try
{
//
try {
val
fileDescriptor
=
uri
?.
let
{
context
.
contentResolver
.
openFileDescriptor
(
it
,
"r"
,
null
)
}
//
val fileDescriptor = uri?.let { context.contentResolver.openFileDescriptor(it, "r", null) }
val
inputStream
=
FileInputStream
(
fileDescriptor
?.
fileDescriptor
)
//
val inputStream = FileInputStream(fileDescriptor?.fileDescriptor)
getSaveContent
=
inputStreamToString
(
inputStream
)
//
getSaveContent = inputStreamToString(inputStream)
}
catch
(
e
:
FileNotFoundException
)
{
//
} catch (e: FileNotFoundException) {
e
.
printStackTrace
()
//
e.printStackTrace()
}
//
}
return
getSaveContent
//
return getSaveContent
}
//
}
//
/**
//
/**
* android 版本 29
//
* android 版本 29
* 檢查文件是否存在
//
* 檢查文件是否存在
*/
//
*/
private
fun
checkFileAndroidQ
(
context
:
Context
,
saveFileName
:
String
):
String
{
//
private fun checkFileAndroidQ(context: Context, saveFileName: String): String {
val
imageUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
//
val imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
val
projection
:
Array
<
String
>
=
arrayOf
(
MediaStore
.
Images
.
Media
.
DISPLAY_NAME
,
MediaStore
.
Images
.
Media
.
_ID
)
//
val projection: Array<String> = arrayOf(MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media._ID)
//
//查詢
//
//查詢
val
contentResolver
=
context
.
contentResolver
//
val contentResolver = context.contentResolver
//
//添加篩選條件
//
//添加篩選條件
val
selection
=
"${MediaStore.Images.Media.DISPLAY_NAME}='$saveFileName'"
//
val selection = "${MediaStore.Images.Media.DISPLAY_NAME}='$saveFileName'"
val
cursor
=
contentResolver
.
query
(
imageUri
,
projection
,
selection
,
null
,
null
)
//
val cursor = contentResolver.query(imageUri, projection, selection, null, null)
//
var
getSaveContent
=
""
//
var getSaveContent = ""
if
(
cursor
!=
null
)
{
//
if (cursor != null) {
while
(
cursor
.
moveToNext
())
{
//
while (cursor.moveToNext()) {
val
fileIdIndex
=
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
_ID
)
//
val fileIdIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID)
val
thumbPath
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
.
buildUpon
().
appendPath
(
cursor
.
getInt
(
fileIdIndex
).
toString
()).
build
().
toString
()
//
val thumbPath = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(cursor.getInt(fileIdIndex).toString()).build().toString()
val
fileUri
=
Uri
.
parse
(
thumbPath
)
//
val fileUri = Uri.parse(thumbPath)
//
try
{
//
try {
val
fileDescriptor
=
contentResolver
.
openAssetFileDescriptor
(
fileUri
,
"r"
,
null
)
//
val fileDescriptor = contentResolver.openAssetFileDescriptor(fileUri, "r", null)
val
inputStream
=
FileInputStream
(
fileDescriptor
?.
fileDescriptor
)
//
val inputStream = FileInputStream(fileDescriptor?.fileDescriptor)
getSaveContent
=
inputStreamToString
(
inputStream
)
//
getSaveContent = inputStreamToString(inputStream)
}
catch
(
e
:
FileNotFoundException
)
{
//
} catch (e: FileNotFoundException) {
e
.
printStackTrace
()
//
e.printStackTrace()
}
//
}
//
//只有在得到的唯一標示符
//
//只有在得到的唯一標示符
if
(!
TextUtils
.
isEmpty
(
getSaveContent
))
{
//
if (!TextUtils.isEmpty(getSaveContent)) {
break
//
break
}
//
}
}
//
}
cursor
.
close
()
//
cursor.close()
}
//
}
return
getSaveContent
//
return getSaveContent
}
//
}
//
/**
//
/**
* android 版本 大於 29
//
* android 版本 大於 29
* 檢查文件是否存在
//
* 檢查文件是否存在
*/
//
*/
@SuppressLint
(
"Range"
)
//
@SuppressLint("Range")
private
fun
checkFileGtAndroidQ
(
context
:
Context
,
saveFileName
:
String
):
String
?
{
//
private fun checkFileGtAndroidQ(context: Context, saveFileName: String): String? {
val
cr
=
context
.
contentResolver
//
val cr = context.contentResolver
val
contentUri
=
MediaStore
.
Files
.
getContentUri
(
"external"
)
//
val contentUri = MediaStore.Files.getContentUri("external")
val
projection
:
Array
<
String
>
=
arrayOf
(
MediaStore
.
Files
.
FileColumns
.
_ID
,
MediaStore
.
Files
.
FileColumns
.
DISPLAY_NAME
)
//
val projection: Array<String> = arrayOf(MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DISPLAY_NAME)
val
selection
=
"${MediaStore.Files.FileColumns.MEDIA_TYPE}=${MediaStore.Files.FileColumns.MEDIA_TYPE_NONE}"
//
val selection = "${MediaStore.Files.FileColumns.MEDIA_TYPE}=${MediaStore.Files.FileColumns.MEDIA_TYPE_NONE}"
val
selectionArgs
:
Array
<
String
>?
=
null
//
val selectionArgs: Array<String>? = null
val
sortOrder
=
null
//
val sortOrder = null
val
cursor
=
cr
.
query
(
contentUri
,
projection
,
selection
,
selectionArgs
,
sortOrder
)
//
val cursor = cr.query(contentUri, projection, selection, selectionArgs, sortOrder)
var
uri
:
Uri
?
=
null
//
var uri: Uri? = null
val
columnIndexID
:
Int
//
val columnIndexID: Int
if
(
cursor
?.
count
==
0
)
{
//
if (cursor?.count == 0) {
Log
.
d
(
TAG
,
"no file"
)
//
Log.d(TAG, "no file")
return
null
//
return null
}
else
{
//
} else {
columnIndexID
=
cursor
?.
getColumnIndexOrThrow
(
MediaStore
.
Files
.
FileColumns
.
_ID
)
!!
//
columnIndexID = cursor?.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID)!!
while
(
cursor
.
moveToNext
())
{
//
while (cursor.moveToNext()) {
val
fileID
=
cursor
.
getLong
(
columnIndexID
)
//
val fileID = cursor.getLong(columnIndexID)
val
fileName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DISPLAY_NAME
))
//
val fileName = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME))
if
(
fileName
==
saveFileName
)
{
//
if (fileName == saveFileName) {
uri
=
Uri
.
withAppendedPath
(
contentUri
,
fileID
.
toString
())
//
uri = Uri.withAppendedPath(contentUri, fileID.toString())
break
//
break
}
//
}
}
//
}
if
(
uri
==
null
)
{
//
if (uri == null) {
Log
.
d
(
TAG
,
"no uri"
)
//
Log.d(TAG, "no uri")
return
null
//
return null
}
else
{
//
} else {
return
try
{
//
return try {
val
fieldException
=
cr
.
openAssetFileDescriptor
(
uri
,
"r"
,
null
)
//
val fieldException = cr.openAssetFileDescriptor(uri, "r", null)
val
inputStream
=
FileInputStream
(
fieldException
?.
fileDescriptor
)
//
val inputStream = FileInputStream(fieldException?.fileDescriptor)
val
sUUID
=
inputStreamToString
(
inputStream
)
//
val sUUID = inputStreamToString(inputStream)
inputStream
.
close
()
//
inputStream.close()
sUUID
//
sUUID
}
catch
(
e
:
IOException
)
{
//
} catch (e: IOException) {
Log
.
d
(
TAG
,
e
.
message
.
toString
())
//
Log.d(TAG, e.message.toString())
null
//
null
}
finally
{
//
} finally {
cursor
.
close
()
//
cursor.close()
}
//
}
}
//
}
}
//
}
}
//
}
/**
//
/**
* 流 轉為 字符串
//
* 流 轉為 字符串
* @param inputStream 流
//
* @param inputStream 流
* @return 轉換完成的字符串
//
* @return 轉換完成的字符串
*/
//
*/
private
fun
inputStreamToString
(
inputStream
:
InputStream
):
String
{
//
private fun inputStreamToString(inputStream: InputStream): String {
val
reader
=
BufferedReader
(
InputStreamReader
(
inputStream
))
//
val reader = BufferedReader(InputStreamReader(inputStream))
val
sb
=
StringBuilder
()
//
val sb = StringBuilder()
try
{
//
try {
reader
.
use
{
r
->
r
.
lineSequence
().
forEach
{
sb
.
append
(
it
)
}
}
//
reader.use { r -> r.lineSequence().forEach { sb.append(it) } }
}
catch
(
e
:
IOException
)
{
//
} catch (e: IOException) {
e
.
printStackTrace
()
//
e.printStackTrace()
}
finally
{
//
} finally {
try
{
//
try {
inputStream
.
close
()
//
inputStream.close()
}
catch
(
e
:
IOException
)
{
//
} catch (e: IOException) {
e
.
printStackTrace
()
//
e.printStackTrace()
}
//
}
}
//
}
return
sb
.
toString
()
//
return sb.toString()
}
//
}
private
fun
save
(
file
:
File
,
content
:
String
):
Boolean
{
private
fun
save
(
file
:
File
,
content
:
String
):
Boolean
{
if
(!
createFile
(
file
,
true
))
{
if
(!
createFile
(
file
,
true
))
{
...
...
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