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

Call back not triggered in ios - fix and Android kotlin code lint fixes #335

Open
wants to merge 6 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 @@ -212,23 +212,25 @@ class BackgroundLocatorPlugin
override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
Keys.METHOD_PLUGIN_INITIALIZE_SERVICE -> {
val args: Map<Any, Any> = call.arguments()
val args: Map<Any, Any>? = call.arguments()

// save callback dispatcher to use it when device reboots
PreferencesManager.saveCallbackDispatcher(context!!, args)
args?.let { PreferencesManager.saveCallbackDispatcher(context!!, it) }

initializeService(context!!, args)
args?.let { initializeService(context!!, it) }
result.success(true)
}
Keys.METHOD_PLUGIN_REGISTER_LOCATION_UPDATE -> {
val args: Map<Any, Any> = call.arguments()
val args: Map<Any, Any>? = call.arguments()

// save setting to use it when device reboots
PreferencesManager.saveSettings(context!!, args)
args?.let { PreferencesManager.saveSettings(context!!, it) }

registerLocator(context!!,
args,
args?.let {
registerLocator(context!!,
it,
result)
}
}
Keys.METHOD_PLUGIN_UN_REGISTER_LOCATION_UPDATE -> {
unRegisterPlugin(context!!, result)
Expand All @@ -240,8 +242,8 @@ class BackgroundLocatorPlugin
return
}

val args: Map<Any, Any> = call.arguments()
updateNotificationText(context!!, args)
val args: Map<Any, Any>? = call.arguments()
args?.let { updateNotificationText(context!!, it) }
result.success(true)
}
else -> result.notImplemented()
Expand All @@ -263,7 +265,7 @@ class BackgroundLocatorPlugin
channel?.setMethodCallHandler(plugin)
}

override fun onNewIntent(intent: Intent?): Boolean {
override fun onNewIntent(intent: Intent): Boolean {
if (intent?.action != Keys.NOTIFICATION_ACTION) {
// this is not our notification
return false
Expand All @@ -272,12 +274,15 @@ class BackgroundLocatorPlugin
val notificationCallback = PreferencesManager.getCallbackHandle(activity!!, Keys.NOTIFICATION_CALLBACK_HANDLE_KEY)
if (notificationCallback != null && IsolateHolderService.backgroundEngine != null) {
val backgroundChannel =
MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger, Keys.BACKGROUND_CHANNEL_ID)
IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger?.let {
MethodChannel(
it, Keys.BACKGROUND_CHANNEL_ID)
}
activity?.mainLooper?.let {
Handler(it)
.post {
backgroundChannel.invokeMethod(Keys.BCM_NOTIFICATION_CLICK,
hashMapOf(Keys.ARG_NOTIFICATION_CALLBACK to notificationCallback))
backgroundChannel?.invokeMethod(Keys.BCM_NOTIFICATION_CLICK,
hashMapOf(Keys.ARG_NOTIFICATION_CALLBACK to notificationCallback))
}
}
}
Expand All @@ -300,4 +305,6 @@ class BackgroundLocatorPlugin
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ internal fun IsolateHolderService.startLocatorService(context: Context) {
}

backgroundChannel =
MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger,
Keys.BACKGROUND_CHANNEL_ID)
IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger?.let {
MethodChannel(
it,
Keys.BACKGROUND_CHANNEL_ID)
}!!
backgroundChannel.setMethodCallHandler(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList

if (backgroundEngine != null) {
val backgroundChannel =
MethodChannel(backgroundEngine?.dartExecutor?.binaryMessenger, Keys.BACKGROUND_CHANNEL_ID)
backgroundEngine?.dartExecutor?.binaryMessenger?.let { MethodChannel(it, Keys.BACKGROUND_CHANNEL_ID) }
Handler(context.mainLooper)
.post {
Log.d("plugin", "sendLocationEvent $result")
backgroundChannel.invokeMethod(Keys.BCM_SEND_LOCATION, result)
backgroundChannel?.invokeMethod(Keys.BCM_SEND_LOCATION, result)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class DisposePluggable : Pluggable {

override fun onServiceDispose(context: Context) {
(PreferencesManager.getCallbackHandle(context, Keys.DISPOSE_CALLBACK_HANDLE_KEY))?.let { disposeCallback ->
val backgroundChannel = MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger,
val backgroundChannel = IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger?.let {
MethodChannel(
it,
Keys.BACKGROUND_CHANNEL_ID)
}
Handler(context.mainLooper)
.post {
backgroundChannel.invokeMethod(Keys.BCM_DISPOSE,
hashMapOf(Keys.ARG_DISPOSE_CALLBACK to disposeCallback))
backgroundChannel?.invokeMethod(Keys.BCM_DISPOSE,
hashMapOf(Keys.ARG_DISPOSE_CALLBACK to disposeCallback))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class InitPluggable : Pluggable {
if (!isInitCallbackCalled) {
(PreferencesManager.getCallbackHandle(context, Keys.INIT_CALLBACK_HANDLE_KEY))?.let { initCallback ->
val initialDataMap = PreferencesManager.getDataCallback(context, Keys.INIT_DATA_CALLBACK_KEY)
val backgroundChannel = MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger,
val backgroundChannel = IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger?.let {
MethodChannel(
it,
Keys.BACKGROUND_CHANNEL_ID)
}
Handler(context.mainLooper)
.post {
backgroundChannel.invokeMethod(Keys.BCM_INIT,
hashMapOf(Keys.ARG_INIT_CALLBACK to initCallback, Keys.ARG_INIT_DATA_CALLBACK to initialDataMap))
backgroundChannel?.invokeMethod(Keys.BCM_INIT,
hashMapOf(Keys.ARG_INIT_CALLBACK to initCallback, Keys.ARG_INIT_DATA_CALLBACK to initialDataMap))
}
}
isInitCallbackCalled = true
Expand Down
9 changes: 5 additions & 4 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 32

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
Expand All @@ -53,6 +50,10 @@ android {
signingConfig signingConfigs.debug
}
}
lint {
disable 'InvalidPackage'
}
namespace 'rekab.app.background_locator_example'
}

flutter {
Expand Down
4 changes: 1 addition & 3 deletions example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rekab.app.background_locator_example"
>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
3 changes: 1 addition & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rekab.app.background_locator_example"
>
package="rekab.app.background_locator_example">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand Down
4 changes: 1 addition & 3 deletions example/android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rekab.app.background_locator_example"
>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
1 change: 0 additions & 1 deletion example/lib/location_service_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class LocationServiceRepository {
int _count = -1;

Future<void> init(Map<dynamic, dynamic> params) async {
//TODO change logs
print("***********Init callback handler");
if (params.containsKey('countInit')) {
dynamic tmpCount = params['countInit'];
Expand Down
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:isolate';
import 'dart:ui';

Expand Down Expand Up @@ -203,9 +202,10 @@ class _MyAppState extends State<MyApp> {
}
}

Future<void> _startLocator() async{
Future<void> _startLocator() async {
Map<String, dynamic> data = {'countInit': 1};
return await BackgroundLocator.registerLocationUpdate(LocationCallbackHandler.callback,
return await BackgroundLocator.registerLocationUpdate(
LocationCallbackHandler.callback,
initCallback: LocationCallbackHandler.initCallback,
initDataCallback: data,
disposeCallback: LocationCallbackHandler.disposeCallback,
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ dev_dependencies:
background_locator:
path: ../

path_provider: ^2.0.8
location_permissions: ^3.0.0+1
path_provider: ^2.0.10
location_permissions: ^4.0.1

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
2 changes: 1 addition & 1 deletion lib/background_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BackgroundLocator {
AndroidSettings androidSettings = const AndroidSettings(),
IOSSettings iosSettings = const IOSSettings()}) async {
if (autoStop) {
WidgetsBinding.instance!.addObserver(AutoStopHandler());
WidgetsBinding.instance.addObserver(AutoStopHandler());
}

final args = SettingsUtil.getArgumentsMap(
Expand Down
2 changes: 1 addition & 1 deletion lib/location_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LocationDto {
json[Keys.ARG_HEADING],
json[Keys.ARG_TIME],
isLocationMocked,
json[Keys.ARG_PROVIDER],
json.containsKey(Keys.ARG_PROVIDER) ? json[Keys.ARG_PROVIDER] : "",
);
}

Expand Down