Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
permission_handler
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
permission_handler
Commits
d69d5a2b
Commit
d69d5a2b
authored
Jul 23, 2018
by
Maurits van Beusekom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented open settings and should show permission rationale API on Android
parent
5ab3ffcc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
4 deletions
+55
-4
android/src/main/kotlin/com/baseflow/permissionhandler/PermissionHandlerPlugin.kt
+39
-4
lib/permission_handler.dart
+16
-0
No files found.
android/src/main/kotlin/com/baseflow/permissionhandler/PermissionHandlerPlugin.kt
View file @
d69d5a2b
...
...
@@ -108,6 +108,10 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
val
permissions
=
Codec
.
decodePermissionGroups
(
call
.
arguments
)
requestPermissions
(
permissions
)
}
call
.
method
==
"shouldShowRequestPermissionRationale"
->
{
val
permission
=
Codec
.
decodePermissionGroup
(
call
.
arguments
)
result
.
success
(
shouldShowRequestPermissionRationale
(
permission
))
}
call
.
method
==
"openAppSettings"
->
{
val
isOpen
=
openAppSettings
()
result
.
success
(
isOpen
)
...
...
@@ -148,6 +152,37 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
return
PermissionStatus
.
GRANTED
}
private
fun
shouldShowRequestPermissionRationale
(
permission
:
PermissionGroup
)
:
Boolean
{
val
activity
=
registrar
.
activity
()
if
(
activity
==
null
)
{
Log
.
d
(
mLogTag
,
"Unable to detect current Activity."
)
return
false
}
val
names
=
getManifestNames
(
permission
)
// if isn't an android specific group then go ahead and return false;
if
(
names
==
null
)
{
Log
.
d
(
mLogTag
,
"No android specific permissions needed for: $permission"
)
return
false
}
if
(
names
.
isEmpty
())
{
Log
.
d
(
mLogTag
,
"No permissions found in manifest for: $permission no need to show request rationale"
)
return
false
}
for
(
name
in
names
)
{
return
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
name
)
}
return
false
}
private
fun
requestPermissions
(
permissions
:
Array
<
PermissionGroup
>)
{
if
(
registrar
.
activity
()
==
null
)
{
Log
.
d
(
mLogTag
,
"Unable to detect current Activity."
)
...
...
@@ -242,8 +277,8 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
return
false
}
try
{
va
r
settingsIntent
=
Intent
()
return
try
{
va
l
settingsIntent
=
Intent
()
settingsIntent
.
action
=
android
.
provider
.
Settings
.
ACTION_APPLICATION_DETAILS_SETTINGS
settingsIntent
.
addCategory
(
Intent
.
CATEGORY_DEFAULT
)
settingsIntent
.
data
=
android
.
net
.
Uri
.
parse
(
"package:"
+
context
.
packageName
)
...
...
@@ -253,9 +288,9 @@ class PermissionHandlerPlugin(private val registrar: Registrar, private var requ
context
.
startActivity
(
settingsIntent
)
return
true
true
}
catch
(
ex
:
Exception
)
{
return
false
false
}
}
...
...
lib/permission_handler.dart
View file @
d69d5a2b
...
...
@@ -18,9 +18,15 @@ class PermissionHandler {
return
Codec
.
decodePermissionStatus
(
status
);
}
/// Open the App settings page.
///
/// Returns [true] if the app settings page could be opened, otherwise [false] is returned.
static
Future
<
bool
>
openAppSettings
()
async
=>
await
_channel
.
invokeMethod
(
"openAppSettings"
);
/// Request the user for access to the supplied list of permissiongroups.
///
/// Returns a [Map] containing the status per requested permissiongroup.
static
Future
<
Map
<
PermissionGroup
,
PermissionStatus
>>
requestPermissions
(
List
<
PermissionGroup
>
permissions
)
async
{
final
jsonData
=
Codec
.
encodePermissionGroups
(
permissions
);
final
status
=
await
_channel
.
invokeMethod
(
...
...
@@ -29,4 +35,14 @@ class PermissionHandler {
return
Codec
.
decodePermissionRequestResult
(
status
);
}
/// Request to see if you should show a rationale for requesting permission.
///
/// This method is only implemented on Android, calling this on iOS always
/// returns [false].
static
Future
<
bool
>
shouldShowRequestPermissionRationale
(
PermissionGroup
permission
)
async
=>
await
_channel
.
invokeMethod
(
'shouldShowRequestPermissionRationale'
,
Codec
.
encodePermissionGroup
(
permission
));
}
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