Skip to content
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ build/
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!**/ios/**/default.perspectivev3

# FVM Version Cache
.fvm/
/.fvmrc
27 changes: 21 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,52 @@ group 'yukams.app.background_locator_2'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.7.20'
ext.kotlin_version = '1.9.0'
repositories {
google()
jcenter()
mavenCentral()
maven { setUrl("https://developer.huawei.com/repo/") }
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:8.7.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.huawei.agconnect:agcp:1.9.1.300'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { setUrl("https://developer.huawei.com/repo/") }
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29
namespace 'yukams.app.background_locator_2'
compileSdkVersion 35

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

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '17'
}

defaultConfig {
minSdkVersion 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
targetSdkVersion 35
}
lintOptions {
disable 'InvalidPackage'
Expand All @@ -41,7 +56,7 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.google.android.gms:play-services-location:21.0.1"
implementation 'com.huawei.hms:location:6.12.0.300'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.material:material:1.0.0'
}
2 changes: 1 addition & 1 deletion 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-7.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package yukams.app.background_locator_2

import android.Manifest
Expand All @@ -6,7 +7,7 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import com.google.android.gms.location.LocationRequest
import com.huawei.hms.location.LocationRequest
import io.flutter.FlutterInjector
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.dart.DartExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList
?: if (context != null) {
backgroundEngine = FlutterEngine(context)
backgroundEngine?.dartExecutor?.binaryMessenger
}else{
} else {
messenger
}
}
Expand Down Expand Up @@ -104,13 +104,16 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList
private fun getNotification(): Notification {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Notification channel is available in Android O and up
val channelName = notificationChannelName ?: "Picap"
var channelID = Keys.CHANNEL_ID ?: "picap_locator"
val channel = NotificationChannel(
Keys.CHANNEL_ID, notificationChannelName,
channelID, channelName,
NotificationManager.IMPORTANCE_LOW
)

(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
.createNotificationChannel(channel)
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
notificationManager?.createNotificationChannel(channel)
}

val intent = Intent(this, getMainActivityClass(this))
Expand Down Expand Up @@ -139,13 +142,19 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.e("IsolateHolderService", "onStartCommand => intent.action : ${intent?.action}")
if(intent == null) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (intent == null) {
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
Log.e("IsolateHolderService", "app has crashed, stopping it")
stopSelf()
}
else {
} else {
return super.onStartCommand(intent, flags, startId)
}
}
Expand All @@ -155,6 +164,7 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList
isServiceRunning = false
shutdownHolderService()
}

ACTION_START == intent?.action -> {
if (isServiceRunning) {
isServiceRunning = false
Expand All @@ -166,6 +176,7 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList
startHolderService(intent)
}
}

ACTION_UPDATE_NOTIFICATION == intent?.action -> {
if (isServiceRunning) {
updateNotification(intent)
Expand Down Expand Up @@ -271,6 +282,7 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList
Keys.METHOD_SERVICE_INITIALIZED -> {
isServiceRunning = true
}

else -> result.notImplemented()
}

Expand All @@ -288,7 +300,7 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList

private fun getLocationClient(context: Context): BLLocationProvider {
return when (PreferencesManager.getLocationClient(context)) {
LocationClient.Google -> GoogleLocationProviderClient(context, this)
LocationClient.Huawei -> HuaweiLocationProviderClient(context, this)
LocationClient.Android -> AndroidLocationProviderClient(context, this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Keys {
val DISPOSE_CALLBACK_HANDLE_KEY = "DISPOSE_CALLBACK_HANDLE_KEY"

@JvmStatic
val CHANNEL_ID = "app.yukams/locator_plugin"
val CHANNEL_ID = "picap_locator"

@JvmStatic
val BACKGROUND_CHANNEL_ID = "app.yukams/locator_plugin_background"
val BACKGROUND_CHANNEL_ID = "picap_locator_background"

@JvmStatic
val METHOD_SERVICE_INITIALIZED = "LocatorService.initialized"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PreferencesManager {
val sharedPreferences =
context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
val client = sharedPreferences.getInt(Keys.SETTINGS_ANDROID_LOCATION_CLIENT, 0)
return LocationClient.fromInt(client) ?: LocationClient.Google
return LocationClient.fromInt(client) ?: LocationClient.Huawei
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package yukams.app.background_locator_2.provider

import android.annotation.SuppressLint
import android.content.Context
import com.google.android.gms.location.*
import android.os.Looper
import com.huawei.hms.location.*

class GoogleLocationProviderClient(context: Context, override var listener: LocationUpdateListener?) : BLLocationProvider {
class HuaweiLocationProviderClient(context: Context, override var listener: LocationUpdateListener?) : BLLocationProvider {
private val client: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context)
private val locationCallback = LocationListener(listener)

Expand All @@ -14,7 +15,7 @@ class GoogleLocationProviderClient(context: Context, override var listener: Loca

@SuppressLint("MissingPermission")
override fun requestLocationUpdates(request: LocationRequestOptions) {
client.requestLocationUpdates(getLocationRequest(request), locationCallback, null)
client.requestLocationUpdates(getLocationRequest(request), locationCallback, Looper.getMainLooper())
}

private fun getLocationRequest(request: LocationRequestOptions): LocationRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package yukams.app.background_locator_2.provider

enum class LocationClient(val value: Int) {
Google(0), Android(1);
Huawei(0), Android(1);

companion object {
fun fromInt(value: Int) = values().firstOrNull { it.value == value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package yukams.app.background_locator_2.provider

import android.location.Location
import android.os.Build
import com.google.android.gms.location.LocationResult
import com.huawei.hms.location.LocationResult
import yukams.app.background_locator_2.Keys
import java.util.HashMap

Expand All @@ -29,7 +29,7 @@ class LocationParserUtil {
Keys.ARG_HEADING to location.bearing,
Keys.ARG_TIME to location.time.toDouble(),
Keys.ARG_PROVIDER to location.provider,
)
) as HashMap<Any, Any>
}

fun getLocationMapFromLocation(location: LocationResult?): HashMap<Any, Any>? {
Expand Down
18 changes: 15 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ if (flutterVersionName == null) {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'

android {
compileSdkVersion 31
namespace 'co.picap.passenger'
compileSdkVersion 35

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -36,11 +38,20 @@ android {
disable 'InvalidPackage'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '17'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "yukams.app.background_locator_example"
applicationId "co.picap.passenger"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -64,4 +75,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.huawei.hms:location:6.12.0.300'
}
3 changes: 1 addition & 2 deletions example/android/app/src/debug/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="yukams.app.background_locator_example"
>
package="co.picap.passenger">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
42 changes: 24 additions & 18 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="yukams.app.background_locator_example"
>
package="co.picap.passenger">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


<!-- io.flutter.app.FlutterApplication is an android.app.Application that
Expand All @@ -17,45 +17,51 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:label="background_locator_example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
>
android:icon="@mipmap/ic_launcher"
android:label="background_locator_example">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
>
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:resource="@style/NormalTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="yukams.app.background_locator_2.BootBroadcastReceiver"
<receiver
android:name="yukams.app.background_locator_2.BootBroadcastReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name="yukams.app.background_locator_2.IsolateHolderService"
android:permission="android.permission.FOREGROUND_SERVICE"
android:exported="true"
android:foregroundServiceType = "location"
/>
android:foregroundServiceType="location"
android:permission="android.permission.FOREGROUND_SERVICE" />

<meta-data
android:name="flutterEmbedding"
android:value="2" />

<meta-data android:name="flutterEmbedding" android:value="2"/>
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="appid=100986425" />

</application>
</manifest>
Loading