Closed chirag-chopra closed 4 months ago
For problems with certain Android devices, see https://dontkillmyapp.com
I have already checked and your example application downloaded from play store is working fine. There is something issue with code. Please check our log file. As we are also getting
Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Don’t use a “self-signed” certificate.
in Server side APIs? @christocracy
Yes. If your server is using a "self-signed" certificate, you cannot use an https
url. You must use http
.
ohk, and have you checked vivo not working.txt log file. Why locations are not working on that device, is there any issue like this on vivo device or any other setup or configuration we need to do. Because example app downloaded from play store and checked on your server is working fine..
There is nothing unusual in your Vivo logs. See https://dontkillmyapp.com
Then go outside and move > 1km.
already checked with the same, all the four devices are together
we have checked ssl certificate, our server is using lets encrypt and we are able to make all network calls, Our certificate and we have also implemented more then 20 api alls are working fine. Expect your background location in some devices @christocracy
This issue is stale because it has been open for 30 days with no activity.
We are still facing this issue, @christocracy please reply
Response: 0, java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. Even others http request are working fine
This plugin uses OkHttp
for its http client.
is there any solution available? @christocracy
Is there anything in that thread which seems interesting to you?
I’m not hearing about this problem from anyone else.
Any chance of introducing a Config property that would disable SSL/TLS certificate checking, say for enabling testing in dev environments that are using self-signed certs?
I don’t know. Does OkHttp allow it?
I don’t know. Does OkHttp allow it?
Don't know. But on second thought I'm just trusting the self-signed certs explicitly on my dev machine/device.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Your Environment
flutter doctor
): Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.10.5, on macOS 13.3.1 22E261 darwin-x64, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.72.2) [✓] Connected device (3 available) [✓] Network resources• No issues found!
/// Receive events from BackgroundGeolocation in Headless state. @pragma('vm:entry-point') void backgroundGeolocationHeadlessTask(bg.HeadlessEvent headlessEvent) async { switch (headlessEvent.name) { case bg.Event.BOOT: bg.State state = await bg.BackgroundGeolocation.state; print("📬 didDeviceReboot: ${state.didDeviceReboot}"); break; case bg.Event.TERMINATE: try { bg.Location location = await bg.BackgroundGeolocation.getCurrentPosition( samples: 1, extras: {"event": "terminate", "headless": true}); print("[getCurrentPosition] Headless: $location"); } catch (error) { print("[getCurrentPosition] Headless ERROR: $error"); } break; case bg.Event.HEARTBEAT: break; case bg.Event.LOCATION: bg.Location location = headlessEvent.event; print(location); break; case bg.Event.MOTIONCHANGE: bg.Location location = headlessEvent.event; print(location); break; case bg.Event.GEOFENCE: bg.GeofenceEvent geofenceEvent = headlessEvent.event; print(geofenceEvent); break; case bg.Event.GEOFENCESCHANGE: bg.GeofencesChangeEvent event = headlessEvent.event; print(event); break; case bg.Event.SCHEDULE: bg.State state = headlessEvent.event; print(state); break; case bg.Event.ACTIVITYCHANGE: bg.ActivityChangeEvent event = headlessEvent.event; print(event); break; case bg.Event.HTTP: bg.HttpEvent event = headlessEvent.event; print(event); break; case bg.Event.POWERSAVECHANGE: bool enabled = headlessEvent.event; print(enabled); break; case bg.Event.CONNECTIVITYCHANGE: bg.ConnectivityChangeEvent event = headlessEvent.event; print(event); break; case bg.Event.ENABLEDCHANGE: bool enabled = headlessEvent.event; print(enabled); break; case bg.Event.AUTHORIZATION: bg.AuthorizationEvent event = headlessEvent.event; print(event); bg.BackgroundGeolocation.setConfig(bg.Config( url: "https://example.com/AddbackgroundLocation", headers: {"Authorization": "Bearer ${prefs!.getString('token')}"})); break; } }
/// Receive events from BackgroundFetch in Headless state. @pragma('vm:entry-point') void backgroundFetchHeadlessTask(HeadlessTask task) async { String taskId = task.taskId;
// Is this a background_fetch timeout event? If so, simply #finish and bail-out. if (task.timeout) { BackgroundFetch.finish(taskId); return; }
// print("[BackgroundFetch] HeadlessTask: $taskId"); try { await bg.BackgroundGeolocation.getCurrentPosition( samples: 1, timeout: 30, extras: {"event": "background-fetch", "headless": true}) .then((value) { print("[location] $value"); }) .onError((error, stackTrace) {}) .catchError((error) {}); } catch (error) { print("[location] ERROR: $error"); }
// SharedPreferences prefs = await SharedPreferences.getInstance(); // int count = 0; // if (prefs.get("fetch-count") != null) { // // count = prefs.getInt("fetch-count"); // } // prefs.setInt("fetch-count", ++count); // print('[BackgroundFetch] count: $count');
BackgroundFetch.finish(taskId); }
Future sendMyLocation() async { bool isLocService = await Permission.locationWhenInUse.serviceStatus.isEnabled; if (isLocService) { bg.BackgroundGeolocation.getCurrentPosition(samples: 1, timeout: 30) .then((value) async { List placemarks = await placemarkFromCoordinates(
value.coords.latitude, value.coords.longitude);
final String finalAddress =
"${placemarks[0].name}, ${placemarks[0].subLocality}, ${placemarks[0].thoroughfare}, ${placemarks[0].locality}, ${placemarks[0].postalCode}, ${placemarks[0].administrativeArea}, ${placemarks[0].country}";
} }
finishYourDayInBg() async { SharedPreferences prefs = await SharedPreferences.getInstance(); // check if location ON or OFF bool isLocService = await Permission.locationWhenInUse.serviceStatus.isEnabled; if (isLocService) { bg.BackgroundGeolocation.getCurrentPosition(samples: 1, timeout: 30) .then((value) async { List placemarks = await placemarkFromCoordinates(
value.coords.latitude, value.coords.longitude);
final finalAddress =
"${placemarks[0].name}, ${placemarks[0].subLocality}, ${placemarks[0].thoroughfare}, ${placemarks[0].locality}, ${placemarks[0].postalCode}, ${placemarks[0].administrativeArea}, ${placemarks[0].country}";
} }
@pragma('vm:entry-point') Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
if (Firebase.apps.isEmpty) {
await Firebase.initializeApp();
}
// finish if (message.notification!.body!.toLowerCase() == 'your day is finished') { finishYourDayInBg(); }
// location if (message.notification!.body!.toLowerCase() == 'location') { // final SharedPreferences prefs = await SharedPreferences.getInstance(); sendMyLocation(); }
// will recieve after logout if (message.notification!.body!.toLowerCase() == 'locStart') { // final SharedPreferences prefs = await SharedPreferences.getInstance(); BackgroundFetch.start(); }
// will recieve after logout if (message.notification!.body!.toLowerCase() == 'logout') { // final SharedPreferences prefs = await SharedPreferences.getInstance(); BackgroundFetch.stop(); bg.BackgroundGeolocation.stop(); await bg.BackgroundGeolocation.removeListeners(); // ========================= LOGOUT STUFF START ==================== SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.clear(); Directory oneTry = await getTemporaryDirectory(); var twoTry;
}
if (message.notification!.body!.toLowerCase() == 'your day is about to finish') { BackgroundFetch.stop(); bg.BackgroundGeolocation.stop(); await bg.BackgroundGeolocation.removeListeners(); } }
void main() async { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); HttpOverrides.global = PostHttpOverrides(); camerass = await availableCameras(); prefs = await SharedPreferences.getInstance(); // firebase setup await Firebase.initializeApp(); // 2. Instantiate Firebase Messaging FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; PlatformDispatcher.instance.onError = (error, stack) { FirebaseCrashlytics.instance.recordError(error, stack, fatal: true); return true; };
Directory dir = Platform.isAndroid ? await getApplicationSupportDirectory() : await getApplicationDocumentsDirectory();
isar = await Isar.open([ DashboardSchema, StartdaySchema, DrawerSchema, MarketSchema, DistributorSchema, RetailerSchema, RetailerClassSchema, RetailerTypeSchema, ProductSchema, CategorySchema, NonPCallReasonSchema, OrderBookingSchema, OrderDetailSchema, OrderRetailerStockSchema, OrderStockDetailSchema, PromotionalActivitySchema, PromotionalActivityDetailSchema, OtherActivityTypeSchema, OtherActivityTypeDropdownSchema, MeetingSchema, MeetingTypeSchema, LeadStatusSchema, ], directory: dir.path);
if (await checkIfInternetWorking() == true) { OnInitStart().storeStartdayItems(); } fbMessaging = FirebaseMessaging.instance; // Register BackgroundGeolocation headless-task. bg.BackgroundGeolocation.registerHeadlessTask( backgroundGeolocationHeadlessTask); BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); runApp(const MyApp()); fbMessaging!.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true); // 3. On iOS, this helps to take the user permissions NotificationSettings settings = await fbMessaging!.requestPermission( alert: true, badge: true, provisional: false, sound: true); if (settings.authorizationStatus == AuthorizationStatus.authorized) { // For handling the received notifications FirebaseMessaging.onMessage.listen((RemoteMessage message) async { if (message.notification!.body!.toLowerCase() == 'logout') { BackgroundFetch.stop(); bg.BackgroundGeolocation.stop(); await bg.BackgroundGeolocation.removeListeners(); // ========================= LOGOUT STUFF START ==================== SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.clear(); Directory oneTry = await getTemporaryDirectory(); var twoTry; if (Platform.isAndroid) { twoTry = await getExternalStorageDirectory(); } else { twoTry = await getApplicationDocumentsDirectory(); } List? threeTry = await getExternalCacheDirectories();
Directory fourTry = await getApplicationSupportDirectory();
Directory fiveTry = await getApplicationDocumentsDirectory();
if (oneTry.existsSync()) {
oneTry.deleteSync(recursive: true);
}
if (twoTry != null) {
if (twoTry.existsSync()) {
twoTry.deleteSync(recursive: true);
}
}
if (threeTry != null) {
if (threeTry[0].existsSync()) {
fourTry.deleteSync(recursive: true);
}
}
if (fourTry.existsSync()) {
fourTry.deleteSync(recursive: true);
}
if (fiveTry.existsSync()) {
fiveTry.deleteSync(recursive: true);
}
await isar!.writeTxn(() async {
isar!.dashboards.clear();
isar!.startdays.clear();
isar!.markets.clear();
isar!.distributors.clear();
isar!.retailers.clear();
isar!.retailerClass.clear();
isar!.retailerTypes.clear();
isar!.products.clear();
isar!.categorys.clear();
isar!.nonPCallReasons.clear();
isar!.orderBookings.clear();
isar!.orderDetails.clear();
isar!.orderRetailerStocks.clear();
isar!.orderStockDetails.clear();
isar!.promotionalActivitys.clear();
isar!.promotionalActivityDetails.clear();
isar!.otherActivityTypes.clear();
isar!.otherActivityTypeDropdowns.clear();
isar!.meetings.clear();
isar!.drawers.clear();
});
Get.off(() => const LoginScreen());
CustomSuccessSnackBar(txt: 'User is Logout');
// ========================= LOGOUT STUFF END ======================
}
// will recieve after logout
if (message.notification!.body!.toLowerCase() == 'locStart') {
BackgroundFetch.start();
}
if (message.notification!.body!.toLowerCase() != 'logout' &&
message.notification!.body!.toLowerCase() != 'locStart' &&
message.notification!.body!.toLowerCase() != 'location') {
// RemoteNotification notification = message.notification!;
// AppleNotification apple = event.notification!.apple!;
// AndroidNotification androidNotification =
// message.notification!.android!;
} }
class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState();
}
class _MyAppState extends State with WidgetsBindingObserver {
// Platform messages are asynchronous, so we initialize in an async method.
Future initPlatformState() async {
// Configure BackgroundFetch.
int status = await BackgroundFetch.configure(
BackgroundFetchConfig(
forceAlarmManager: true,
minimumFetchInterval: 15,
stopOnTerminate: false,
enableHeadless: true,
startOnBoot: true,
requiresBatteryNotLow: false,
requiresCharging: false,
requiresStorageNotLow: false,
requiresDeviceIdle: false,
requiredNetworkType: NetworkType.NONE), (String taskId) async {
BackgroundFetch.finish(taskId);
}, (String taskId) async {
// <-- Task timeout handler.
// This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId)
print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId");
BackgroundFetch.finish('taskId');
});
print('[BackgroundFetch] configure success: $status');
}
@override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this);
}
// @override // void dispose() { // WidgetsBinding.instance.removeObserver(this); // super.dispose(); // }
@override void didChangeAppLifecycleState(AppLifecycleState state) async { if (state == AppLifecycleState.resumed) { final SharedPreferences prefs = await SharedPreferences.getInstance(); if (prefs.containsKey('startdayTime')) { if (!DateTime.parse(prefs.getString('startdayTime')!).isToday()) { try { Get.offAll(() => const StartDayScreen()); } catch (e) { return; } } } } super.didChangeAppLifecycleState(state); }
@override Widget build(BuildContext context) { print('TOKEN : ${prefs!.getString('token')}'); return ScreenUtilInit( designSize: const Size(360, 800), minTextAdapt: true, splitScreenMode: false, useInheritedMediaQuery: true, builder: (context, snapshot) { return GetMaterialApp( // showPerformanceOverlay: true, // showSemanticsDebugger: true, // debugShowMaterialGrid: true, navigatorKey: navigatorKey, scaffoldMessengerKey: snackbarKey, debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, fontFamily: 'Montserrat'), home: const SplashScreen()); }); } }
Logs: Below Working mi working.txt
Below Working redmi working.txt
Below Not Working samsung not working.txt
Below Not Working vivo not working.txt