OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

[Bug]: Unable to Receive Push Notification on Android

Open hwasiq15 opened this issue 10 months ago • 3 comments

What happened?

I have set up the OneSignal dashboard and configured Firebase, but the app neither receives push notifications nor prompts for notification permission. I’ve double-checked the setup, but it still doesn’t seem to work. Any suggestions on what might be missing or causing this issue?

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize Firebase
  await Firebase.initializeApp();
  configureOneSignal();

  runApp(const MyApp());
}

// Configure OneSignal SDK
void configureOneSignal() {
  // Enable verbose logging for development
  OneSignal.Debug.setLogLevel(OSLogLevel.verbose);

  // Initialize OneSignal with the app ID
  OneSignal.initialize("b38128ff-0561-499c-ab67-87fb6c3b9911");

  // Request notification permissions
  OneSignal.Notifications.requestPermission(true).then((granted) {
    if (granted) {
      debugPrint("Notification permission granted.");
    } else {
      debugPrint("Notification permission denied.");
    }
  });
}

Steps to reproduce?

Set up the OneSignal dashboard and completed the configuration.
Integrated Firebase into the app and ensured the connection with OneSignal.
Installed the app on a test device and launched it.
Noticed the following issues:
The app does not ask for notification permissions when launched.
Push notifications are not received on the device.

What did you expect to happen?

I expected the app to prompt the user for notification permissions upon launching for the first time. After granting permission, I expected the app to successfully receive and display push notifications sent via the OneSignal dashboard.

OneSignal Flutter SDK version

5.2.9

Which platform(s) are affected?

  • [ ] iOS
  • [x] Android

Relevant log output

D/OneSignal(25249): [main] initWithContext: SDK already initialized
D/OneSignal(25249): [main] Retrieving service interface com.onesignal.inAppMessages.IInAppMessagesManager
D/OneSignal(25249): [main] Already instantiated: com.onesignal.inAppMessages.internal.InAppMessagesManager@46e2990
D/OneSignal(25249): [main] InAppMessagesManager.addLifecycleListener(listener: com.onesignal.flutter.OneSignalInAppMessages@8f1c289)
D/OneSignal(25249): [main] Retrieving service interface com.onesignal.inAppMessages.IInAppMessagesManager
D/OneSignal(25249): [main] Already instantiated: com.onesignal.inAppMessages.internal.InAppMessagesManager@46e2990
D/OneSignal(25249): [main] InAppMessagesManager.addClickListener(listener: com.onesignal.flutter.OneSignalInAppMessages@8f1c289)


9): [DefaultDispatcher-worker-3] HttpClient: Request Sent = POST https://api.onesignal.com/apps/b38128ff-0561-499c-ab67-87fb6c3b9911/users - Body: {"subscriptions":[{"type":"AndroidPush","token":"","enabled":false,"notification_types":-8,"sdk":"050126","device_model":"Infinix X663","device_os":"12","rooted":false,"net_type":0,"carrier":"Telenor","app_version":"1"}],"properties":{"timezone_id":"Asia\/Karachi","language":"en"},"refresh_device_metadata":true} - Headers: Accept=[application/vnd.onesignal.v1+json], Content-Type=[application/json; charset=UTF-8], OneSignal-Install-Id=[d4366c9b-2751-4570-afd7-ba562b007452], OneSignal-Subscription-Id=[local-2521de17-08a7-4341-8627-4c0ec7a45b75], SDK-Version=[onesignal/android/050126], SDK-Wrapper=[onesignal/flutter/050209]

 Operation execution failed, retrying: [{"name":"login-user","appId":"b38128ff-0561-499c-ab67-87fb6c3b9911","onesignalId":"local-ab4481c7-0b59-4664-ad28-42c06b6f3779","id":"ea84622b-befa-4b57-889e-dfbfbb72859a"}, {"name":"create-subscription","appId":"b38128ff-0561-499c-ab67-87fb6c3b9979","onesignalId":"local-ab4481c7-0b59-4664-ad28-42c06b6f3779","subscriptionId":"local-2521de17-08a7-4341-8627-4c0ec7a45b75","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"4847d83a-8cc6-429d-a97c-25e883892091"}, {"name":"update-subscription","appId":"b38128ff-0561-499c-ab67-87fb6c3b9979","onesignalId":"local-ab4481c7-0b59-4664-ad28-42c06b6f3779","subscriptionId":"local-2521de17-08a7-4341-8627-4c0ec7a45b75","type":"PUSH","enabled":false,"address":"","status":"FIREBASE_FCM_INIT_ERROR","id":"ed5446de-0ea0-4071-a84b-007aa1d965ad"}]

I/OneSignal(25249): [Thread-10] Failed to get Android parameters, trying again in 90 seconds.

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

hwasiq15 avatar Jan 27 '25 13:01 hwasiq15

facing the same issue.

shahdab22 avatar Jan 28 '25 06:01 shahdab22

Facing Same Issue

affan3699 avatar Feb 05 '25 08:02 affan3699

Hi @hwasiq15, I see some errors in the logs you shared. However, these don't look like the full logs, so lots of log statements appear to be missing, so I cannot see the reasons for the errors.

I would assume the request errors are related to your issue. Do you have the full logs?

nan-li avatar Feb 11 '25 03:02 nan-li