Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
A
appzxhy
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
zhouzhi
appzxhy
Commits
2ed3614b
Commit
2ed3614b
authored
Dec 16, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...权限
parent
fd94dcc4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
36 deletions
+41
-36
PermissionUtils.kt
app/src/main/java/com/base/appzxhy/utils/PermissionUtils.kt
+41
-36
No files found.
app/src/main/java/com/base/appzxhy/utils/PermissionUtils.kt
View file @
2ed3614b
package
com.base.
locationsharewhite
.utils
package
com.base.
appzxhy
.utils
import
android.Manifest
import
android.app.Activity
...
...
@@ -11,12 +11,12 @@ import android.os.Build
import
android.os.Environment
import
android.provider.Settings
import
androidx.core.app.ActivityCompat
import
com.base.appzxhy.utils.ActivityLauncher
import
com.base.appzxhy.utils.IntentUtils.intentAppDetailsSettings
import
com.base.appzxhy.utils.LogEx
object
PermissionUtils
{
//region 通知
fun
Context
.
areNotificationsEnabled
():
Boolean
{
val
notificationManager
=
this
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
...
...
@@ -24,7 +24,21 @@ object PermissionUtils {
return
flag
}
fun
Context
.
checkNotificationPermission
():
Boolean
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
POST_NOTIFICATIONS
)
==
PackageManager
.
PERMISSION_GRANTED
}
else
{
return
true
}
}
fun
Context
.
checkAllLocationPermission
():
Boolean
{
return
checkLocationPermission
()
&&
checkBackgroundLocationPermission
()
}
//endregion
//region 储存
fun
Context
.
checkStorePermission
():
Boolean
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
Environment
.
isExternalStorageManager
()
...
...
@@ -35,18 +49,32 @@ object PermissionUtils {
}
}
fun
Context
.
checkNotificationPermission
():
Boolean
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
POST_NOTIFICATIONS
)
==
PackageManager
.
PERMISSION_GRANTED
fun
Context
.
requestStoragePermission
(
launcher
:
ActivityLauncher
,
jumpAction
:
(()
->
Unit
)?
=
null
,
result
:
(
flag
:
Boolean
)
->
Unit
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
val
intent
=
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
)
intent
.
addCategory
(
"android.intent.category.DEFAULT"
)
intent
.
data
=
Uri
.
parse
(
"package:${packageName}"
)
jumpAction
?.
invoke
()
launcher
.
launch
(
intent
)
{
result
.
invoke
(
checkStorePermission
())
}
}
else
{
return
true
launcher
.
launch
(
arrayOf
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
))
{
map
->
result
(
map
.
values
.
all
{
it
})
}
}
}
fun
Context
.
checkAllLocationPermission
():
Boolean
{
return
checkLocationPermission
()
&&
checkBackgroundLocationPermission
()
}
//endregion
//region 定位
fun
Context
.
checkLocationPermission
():
Boolean
{
val
fineLocationPermission
=
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
...
...
@@ -55,7 +83,6 @@ object PermissionUtils {
return
fineLocationPermission
==
PackageManager
.
PERMISSION_GRANTED
&&
accessCoarsePermission
==
PackageManager
.
PERMISSION_GRANTED
;
}
fun
Activity
.
checkLocationPermissionDeniedByUser
():
Boolean
{
val
deniedByUser1
=
...
...
@@ -69,7 +96,6 @@ object PermissionUtils {
return
deniedByUser1
&&
deniedByUser2
}
fun
Context
.
checkBackgroundLocationPermission
():
Boolean
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
ActivityCompat
.
checkSelfPermission
(
...
...
@@ -86,30 +112,6 @@ object PermissionUtils {
return
deniedByUser1
}
fun
Context
.
requestStoragePermission
(
launcher
:
ActivityLauncher
,
jumpAction
:
(()
->
Unit
)?
=
null
,
result
:
(
flag
:
Boolean
)
->
Unit
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
val
intent
=
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
)
intent
.
addCategory
(
"android.intent.category.DEFAULT"
)
intent
.
data
=
Uri
.
parse
(
"package:${packageName}"
)
jumpAction
?.
invoke
()
launcher
.
launch
(
intent
)
{
result
.
invoke
(
checkStorePermission
())
}
}
else
{
launcher
.
launch
(
arrayOf
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
))
{
map
->
result
(
map
.
values
.
all
{
it
})
}
}
}
fun
Activity
.
requestLocationAllowAllTime
(
launcher
:
ActivityLauncher
,
jumpOutAction
:
(()
->
Unit
)?
=
null
,
//跳转到设置
...
...
@@ -158,4 +160,7 @@ object PermissionUtils {
}
}
}
//endregion
}
\ No newline at end of file
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