Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to skip checking access background permission in android #930

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ private void isBackgroundModeEnabled(Result result) {

private void enableBackgroundMode(MethodCall call, Result result) {
final Boolean enable = call.argument("enable");
final Boolean checkBackgroundPermissions = call.argument("checkBackgroundPermissions");
if (locationService != null && enable != null) {
if (locationService.checkBackgroundPermissions()) {
if (!checkBackgroundPermissions || locationService.checkBackgroundPermissions()) {
if (enable) {
locationService.enableBackgroundMode();

Expand Down
10 changes: 8 additions & 2 deletions packages/location/lib/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ class Location implements LocationPlatform {

/// Enables or disables service in the background mode.
@override
Future<bool> enableBackgroundMode({bool? enable = true}) {
return LocationPlatform.instance.enableBackgroundMode(enable: enable);
Future<bool> enableBackgroundMode({
bool? enable = true,
bool? checkBackgroundPermissions = false,
}) {
return LocationPlatform.instance.enableBackgroundMode(
enable: enable,
checkBackgroundPermissions: checkBackgroundPermissions,
);
}

/// Gets the current location of the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

part 'src/method_channel_location.dart';

part 'src/types.dart';

/// The interface that implementations of `location` must extend.
Expand Down Expand Up @@ -53,7 +54,10 @@ class LocationPlatform extends PlatformInterface {
}

/// Enables or disables service in the background mode.
Future<bool> enableBackgroundMode({bool? enable}) {
Future<bool> enableBackgroundMode({
bool? enable,
bool? checkBackgroundPermissions,
}) {
throw UnimplementedError();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ class MethodChannelLocation extends LocationPlatform {
@override
Future<bool> isBackgroundModeEnabled() async {
final result =
await _methodChannel!.invokeMethod('isBackgroundModeEnabled');
await _methodChannel!.invokeMethod('isBackgroundModeEnabled');
return result == 1;
}

/// Enables or disables service in the background mode.
@override
Future<bool> enableBackgroundMode({bool? enable}) async {
Future<bool> enableBackgroundMode({
bool? enable,
bool? checkBackgroundPermissions,
}) async {
final result = await _methodChannel!.invokeMethod(
'enableBackgroundMode',
<String, dynamic>{'enable': enable},
<String, dynamic>{
'enable': enable,
'checkBackgroundPermissions': checkBackgroundPermissions,
},
);

return result == 1;
Expand All @@ -80,7 +86,7 @@ class MethodChannelLocation extends LocationPlatform {
@override
Future<LocationData> getLocation() async {
final resultMap =
await _methodChannel!.invokeMapMethod<String, dynamic>('getLocation');
await _methodChannel!.invokeMapMethod<String, dynamic>('getLocation');
if (resultMap == null) {
throw PlatformException(
code: 'NULL_RESULT',
Expand Down
Loading