local_notifications: Android Notifications not showing, iOS showing correctly
`import ‘package:camera/camera.dart’; import ‘dart:io’; import ‘package:path_provider/path_provider.dart’; import ‘package:image_picker/image_picker.dart’; import ‘package:Unify_Mobile/globals.dart’ as globals; import ‘dart:async’; import ‘package:flutter/foundation.dart’; import ‘package:flutter/material.dart’; import ‘package:local_notifications/local_notifications.dart’;
Future<Null> openCamera(BuildContext context, bool photo) async { cameras = await availableCameras(); if (photo) { //Picture Navigator.push( context, new MaterialPageRoute(builder: (context) => new MyHomePage()), ); } else { //Video } }
List<CameraDescription> cameras;
class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override _MyHomePageState createState() => new _MyHomePageState(); }
class _MyHomePageState extends State<MyHomePage> { Future<File> _imageFile;
Image uploadImage(File file) { return new Image.file(file); }
onNotificationClick(String payload) { // // payload is “some payload” // LocalNotifications.removeNotification(0); print(‘Running in background and received payload: $payload’); }
void sendNotification(String title, String message, int id) async { await LocalNotifications.createNotification( title: title, content: message, id: id, onNotificationClick: new NotificationAction( actionText: “some action”, // Note: only works for iOS callback: onNotificationClick, payload: “some payload”)); }
@override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: const Text(‘Capture’), backgroundColor: Colors.white, actions: <Widget>[ new IconButton( tooltip: ‘Upload to Gallery’, icon: new Icon( Icons.file_upload, ), onPressed: () { _imageFile == null ? globals.Utility.showAlertPopup(context, “Info”, “Photo Required for Upload!”, “”) : sendNotification( “Upload Complete”, “Image has finished processing.”, 0); //True for Stock Camera }, ), ], ), body: new Center( child: new FutureBuilder<File>( future: _imageFile, builder: (BuildContext context, AsyncSnapshot<File> snapshot) { if (snapshot.connectionState == ConnectionState.done && snapshot.error == null) { return new Image.file(snapshot.data); } else if (snapshot.error != null) { return const Text(‘error picking video.’); } else { return const Text(‘You have not yet picked an video.’); } })), floatingActionButton: new FloatingActionButton( onPressed: () { setState(() { _imageFile = ImagePicker.pickImage(); }); }, tooltip: ‘Pick Video’, child: new Icon(Icons.add_a_photo), ), ); } } `
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 31 (13 by maintainers)
@AppleEducate The deprecation and unchecked warnings should not show up with v 0.0.6
@huextrat With v 0.0.6, the minSdk is 16. I tested this out on an AVD with SDK 16 and 27, but haven’t tested on any other SDK between 16-23.
I believe I can make the deprecated messages go away and will be able to lower the min sdk if I change the Android APIs to use the support library. This will be the next thing I look into.
Here’s a few things you can try
First,
flutter cleanfrom your directory root. Fairly often, I find that the updated dependencies don’t actually get pulled in, but a flutter clean should fix this.If that doesn’t work, make sure you’ve done the following:
After this code is run, you can validate the channel is created by going into Settings->Apps and Notifications->(Your app)->App notifications. You should see your category listed there similar to below (highlighted with a red box).
Once you’ve validated the channel was successfully created, then you can create notifications, making sure to provide the same channel info (note: it doesn’t have to be the same exact object, but the value of the channel ‘id’ must be the same)
If after all of that the notification is still not being posted, one other new thing I added in 0.0.3 is better logging. You can turn on logging with
await LocalNotifications.setLogging(true);. It will log a message at different steps in the android code to help debug where it is getting stuck or failing.@AppleEducate Did you mean that the notification doesn’t show up even in the status bar or notification drawer? or that it doesn’t show up on the screen when it is created (as a heads up notification)? (Also @huextrat ) On android, heads up notification behavior is not yet implemented. On iOS, the heads up notification behavior is the default.
Support for vibration is not yet implemented. It’s tracked by #8
Weird. I tested on a few AVDs as well as my own Pixel with the latest OS and haven’t had any issues. Perhaps this indicates I need to add more/better logging to help debug these types of issues?
Regarding the iOS and Android differences… Android uses an “opt-out” model for notifications: all apps by default have permissions to send notifications and the user has the ability to block notifications for a certain app.
iOS uses an “opt-in” model for notifications: all apps by default do not have permissions to send notifications and the app must explicitly ask the user for permission before being able to do so.